From 9af83462c6f432b77a846a24b4d8efae9bdf0567 Mon Sep 17 00:00:00 2001 From: Tilman Dilo Date: Mon, 9 May 2016 23:37:07 +0200 Subject: [PATCH] crypto/cipher: execute AES-GCM decryption example The decryption example for AES-GCM was not executed, hiding the fact that the provided ciphertext could not be authenticated. This commit adds the required output comment, replaces the ciphertext with a working example, and removes an unnecessary string conversion along the way. Change-Id: Ie6729ca76cf4a56c48b33fb3b39872105faa604b Reviewed-on: https://go-review.googlesource.com/22953 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/crypto/cipher/example_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/crypto/cipher/example_test.go b/src/crypto/cipher/example_test.go index f6cc3865061..9abe782bca5 100644 --- a/src/crypto/cipher/example_test.go +++ b/src/crypto/cipher/example_test.go @@ -44,9 +44,9 @@ func ExampleNewGCMDecrypter() { // The key argument should be the AES key, either 16 or 32 bytes // to select AES-128 or AES-256. key := []byte("AES256Key-32Characters1234567890") - ciphertext, _ := hex.DecodeString("f90fbef747e7212ad7410d0eee2d965de7e890471695cddd2a5bc0ef5da1d04ad8147b62141ad6e4914aee8c512f64fba9037603d41de0d50b718bd665f019cdcd") + ciphertext, _ := hex.DecodeString("1019aa66cd7c024f9efd0038899dae1973ee69427f5a6579eba292ffe1b5a260") - nonce, _ := hex.DecodeString("bb8ef84243d2ee95a41c6c57") + nonce, _ := hex.DecodeString("37b8e8a308c354048d245f6d") block, err := aes.NewCipher(key) if err != nil { @@ -63,7 +63,8 @@ func ExampleNewGCMDecrypter() { panic(err.Error()) } - fmt.Printf("%s\n", string(plaintext)) + fmt.Printf("%s\n", plaintext) + // Output: exampleplaintext } func ExampleNewCBCDecrypter() {