I'm trying to figure out how to sign a piece of data (in this case a string) using golang. So far everything I can find is about signing transactions which wont work for signing pieces of data that is not of a type transaction.
1 Answer
Figured it out:
// convert string key to byte array
byteKey := []byte(`{....}`)
privKey, err := keystore.DecryptKey(byteKey, string(pass))
if err != nil {
log.Fatal("error decrypting key")
} else {
fmt.Printf("key successfully decrypted %v\n", privKey)
}
hash := crypto.Keccak256([]byte("hello"))
sig, err := crypto.Sign(hash, privKey.PrivateKey)
if err != nil {
log.Fatal("error signing data")
} else {
fmt.Println("signature successful ", sig)
}
-
-
-
-
Ah okay, i'm verifying the signatures in smart contracts using solidity, but with golang it's even simpler, literally one command: godoc.org/github.com/ethereum/go-ethereum/…– hextetMar 25, 2018 at 23:24