Simple implementation issue
pedroalbanese opened this issue · comments
Pedro F. Albanese commented
Greetings!
I am having trouble understanding how I supply a private key that is not newly created, e.g. created in a previous command. In short, I need to create key pairs in one command and perform secret key derivation in another command.
As the example:
package main
import (
"github.com/monnand/dhkx"
"flag"
"fmt"
"math/big"
)
var (
key = flag.String("key", "", "Private key.")
pub = flag.String("pub", "", "Public key.")
gen = flag.Bool("gen", false, "Generate asymmetric keypair.")
derive = flag.Bool("derive", false, "Derive shared secret key.")
)
func main() {
flag.Parse()
g, _ := dhkx.GetGroup(14)
if *gen {
// Generate a private key from the group.
// Use the default random number generator.
priv, _ := g.GeneratePrivateKey(nil)
fmt.Printf("Private= %v\n", priv)
// Get the public key from the private key.
pub := priv.Bytes()
fmt.Printf("Public= %x\n", pub)
}
if *derive {
PubKey := dhkx.NewPublicKey([]byte(*pub))
fmt.Printf("PubKey: %v\n", PubKey)
// Compute the key
k, _ := g.ComputeKey(PubKey, *dhkx.DHKey(*key))
// Get the key in the form of []byte
key := k.Bytes()
fmt.Printf("Key: %x\n", key)
}
}
But I don't understood how to transform the parameter provieded by flag in to dhkx.DHKey:
.\main.go:42:43: cannot convert *key (type string) to type dhkx.DHKey
How to inform the private key?
Thanks in advance!