Google Tink with Go (ECDSA)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 ECDSA 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_tink03 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.ECDSAP256KeyTemplate()) // keyPriv, _ := keyset.NewHandle(signature.ECDSAP384KeyTemplate()) // keyPriv, _ := keyset.NewHandle(signature.ECDSAP521KeyTemplate()) 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) fmt.Printf("Key: %s\n\n", exportedPriv) exportedPub := &keyset.MemReaderWriter{} insecurecleartextkeyset.Write(keyPub, exportedPub) fmt.Printf("Key: %s\n\n", exportedPub) } }