]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/cipher: execute AES-GCM decryption example
authorTilman Dilo <tilman.dilo@gmail.com>
Mon, 9 May 2016 21:37:07 +0000 (23:37 +0200)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 9 May 2016 23:03:55 +0000 (23:03 +0000)
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 <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/crypto/cipher/example_test.go

index f6cc38650610ad23fa474df2a913eabbb5ef106e..9abe782bca54aec85416bb8a72ea64127b934adb 100644 (file)
@@ -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() {