1
0
mirror of https://github.com/golang/go synced 2024-11-23 18:40:03 -07:00

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 <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Tilman Dilo 2016-05-09 23:37:07 +02:00 committed by Brad Fitzpatrick
parent d88261fb65
commit 9af83462c6

View 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() {