I'm trying to generate private key using the Extract() in the Master interface of the ibe package, here's the link of the package,"https://godoc.org/v.io/x/lib/ibe#Master". In the package, the input of Extract is id, and consist of {0,1}*, so I convert Mac id to binary string first, and then use the binary string to generate correspond private key. My code is like this.
package main
import (
"fmt"
"v.io/x/lib/ibe"
)
var Macid = "00055DNEFF"
var id string
var PrivateKey string
func stringToBin(Macid string) (id string) {
for _, c := range Macid {
id = fmt.Sprintf("%s%b", id, c)
}
return
}
type Master string
func (master Master) Extract(id string) (PrivateKey, error) {
return PrivateKey
}
func main() {
fmt.Println("MacID is " + Macid + ", public key is" + stringToBin(Macid) + ", private key is" + ibe.Extract(id))
}
But I always got errors
$ go build pkg.go
command-line-arguments
./pkg.go:27: PrivateKey is not a type
./pkg.go:33: undefined: ibe in ibe.Extract
I'm all new to go, and I have read the tour of go, but I couldn't get it. Can anyone help me with this? Thank you.
There are 2 implementations of Master provided in the ibe package (bb1 and bb2). These can be accessed using either ibe.SetupBB1() or ibe.SetupBB2()
package main
import (
"fmt"
"log"
"v.io/x/lib/ibe"
)
var Macid = "00055DNEFF"
func stringToBin(Macid string) (id string) {
for _, c := range Macid {
id = fmt.Sprintf("%s%b", id, c)
}
return
}
func main() {
bb2Master, err := ibe.SetupBB2()
// or
// bb1Master, err := ibe.SetupBB1()
if err != nil {
log.Fatal(err)
}
id := stringToBin(Macid)
privateKey, err := bb2Master.Extract(id)
if err != nil {
log.Fatal(err)
}
fmt.Printf("MacID is %v, private key is %v", Macid, privateKey)
// etc...
// privateKey.Decrypt(C, m)
}
@Joshua Wales
package main
import (
"fmt"
"log"
"v.io/x/lib/ibe"
)
var Macid = "00055DNEFF"
func stringToBin(Macid string) (id string) {
for _, c := range Macid {
id = fmt.Sprintf("%s%b", id, c)
}
return
}
func main() {
bb1Master, err := ibe.SetupBB1()
if err != nil {
log.Fatal(err)
}
id := stringToBin(Macid)
privateKey, err := bb1Master.Extract(id)
if err != nil {
log.Fatal(err)
}
fmt.Printf("MacID is %v, private key is %v", Macid, privateKey)
m := []byte("HelloAuthentication")
overhead := bb1Master.Params().CiphertextOverhead()
C := make([]byte, len(m)+overhead)
if err := bb1Master.Params().Encrypt(Macid, m, C); err != nil {
log.Fatal(err)
}
fmt.Printf("Ciphertext is : ", bb1Master.Params().Encrypt(Macid, m, C))
if err := privateKey.Decrypt(C, m); err != nil {
log.Fatal(err)
}
fmt.Printf("Decrypted text is : ", privateKey.Decrypt(C, m))
}
@