Google Tink with Go (MAC)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 MAC for a message: |
Coding
The following is the Golang code:
package main import ( "fmt" "github.com/google/tink/go/mac" "github.com/google/tink/go/keyset" "github.com/google/tink/go/insecurecleartextkeyset" "os" ) func main() { msg:="This is a test" argCount := len(os.Args[1:]) if (argCount>0) { msg= (os.Args[1])} // key,_ := keyset.NewHandle(mac.HMACSHA256Tag256KeyTemplate()) key,_ := keyset.NewHandle(mac.HMACSHA256Tag128KeyTemplate()) // MAC mac.HMACSHA256Tag128KeyTemplate() // MAC mac.HMACSHA256Tag256KeyTemplate() // MAC mac.HMACSHA512Tag256KeyTemplate() // MAC mac.HMACSHA512Tag512KeyTemplate() m, _ := mac.New(key) mac, _ := m.ComputeMAC([]byte(msg)) res:=m.VerifyMAC(mac, []byte(msg)) if (res!=nil) { fmt.Printf("MAC failed!") } else { fmt.Printf("Message: %s\n\n", msg) fmt.Printf("MAC: %x\n", mac) fmt.Printf("\nMAC success!\n\n") exportedPriv := &keyset.MemReaderWriter{} insecurecleartextkeyset.Write(key, exportedPriv) fmt.Printf("Key: %s\n\n", exportedPriv) } }