Google Tink with Go (Ed25519)Google has released Tink and which is a multi-language, cross-platform cryptographic library. With OpenSSL we have complex bindings and which were often focused on specific systems, such as for DLLs in Windows systems. Tink is open-source and focuses on creating simple APIs and which should make the infrastructure more portable. In this case will will find the Ed25519 signature for a message, and where we use a private key to sign, and a public key to prove the signature: |
Coding
The following is the Golang code:
// https://asecuritysite.com/encryption/go_tink04 package main import ( "fmt" "os" "github.com/google/tink/go/keyset" "github.com/google/tink/go/signature" "github.com/google/tink/go/insecurecleartextkeyset" ) func main() { msg:="This is a test" argCount := len(os.Args[1:]) if (argCount>0) { msg= (os.Args[1])} keyPriv, _ := keyset.NewHandle(signature.ED25519KeyTemplate()) keyPub, _ := keyPriv.Public() s, _ := signature.NewSigner(keyPriv) a, _ := s.Sign([]byte(msg)) v, _ := signature.NewVerifier(keyPub) res := v.Verify(a, []byte(msg)) if (res != nil) { fmt.Println("Signature verification failed") } else { fmt.Printf("Message: %s\n\n", msg) fmt.Printf("Signature: %x\n", a) fmt.Printf("\nPrivate Key: %s\n\n", keyPriv) fmt.Printf("Public Key: %s\n\n", keyPub) fmt.Println("Signature verification succeeded.\n\n") exportedPriv := &keyset.MemReaderWriter{} insecurecleartextkeyset.Write(keyPriv, exportedPriv) exportedPub := &keyset.MemReaderWriter{} insecurecleartextkeyset.Write(keyPub, exportedPub) fmt.Printf("Private Key ID: %d\n\n", exportedPriv.Keyset.GetPrimaryKeyId()) fmt.Printf("Private Key %s:\n\n", exportedPriv.Keyset.GetKey()) fmt.Printf("Public Key ID: %d\n\n", exportedPub.Keyset.GetPrimaryKeyId()) k:=exportedPub.Keyset.GetKey() fmt.Printf("Public Key %s:\n\n", k) } }