Google Tink with Go (AES GCM)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: |
Coding
The following is the Golang code:
package main import ( "fmt" "github.com/google/tink/go/aead" "github.com/google/tink/go/keyset" "github.com/google/tink/go/insecurecleartextkeyset" "os" ) func main() { msg:="This is a test" assoc:="A bit of random" argCount := len(os.Args[1:]) if (argCount>0) { msg= (os.Args[1])} if (argCount>1) { assoc= (os.Args[2])} // Modes are: 128-bit and 256-bit AES CTR, 128-bit and 256-bit AES GCM, and ChaCha20/Poly1205 // key,_ := keyset.NewHandle(aead.AES128CTRHMACSHA256KeyTemplate()) key,_ := keyset.NewHandle(aead.AES128GCMKeyTemplate()) // key,_ := keyset.NewHandle(aead.AES256CTRHMACSHA256KeyTemplate()) // key,_ := keyset.NewHandle(aead.AES256GCMKeyTemplate()) // key,_ := keyset.NewHandle(aead.ChaCha20Poly1305KeyTemplate()) // key,_ := keyset.NewHandle(aead.XChaCha20Poly1305KeyTemplate()) a,_:= aead.New(key) ct, _ := a.Encrypt([]byte(msg), []byte(assoc)) pt, _ := a.Decrypt(ct, []byte(assoc)) fmt.Printf("Message: %s\nAssociated data: %s\n", msg,assoc) fmt.Printf("Cipher text: %x\nPlain text: %s\n\n\n", ct, pt) exportedPriv := &keyset.MemReaderWriter{} insecurecleartextkeyset.Write(key, exportedPriv) fmt.Printf("Key: %s\n\n", exportedPriv) }