0

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.

0

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)
}
  • and how do you verify the signature? is the snippet code also simple? – Nulik Mar 23 '18 at 14:18
  • In golang or solidity? – hextet Mar 25 '18 at 3:19
  • in golang ... ... – Nulik Mar 25 '18 at 18:05
  • 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/… – hextet Mar 25 '18 at 23:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.