From: Adam Langley Date: Sat, 22 Dec 2012 15:50:11 +0000 (-0500) Subject: crypto/des: add an example to demonstrate EDE2 operation. X-Git-Tag: go1.1rc2~1560 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8f1d170fc6758842a1dc89075a050716fa4dc6c3;p=gostls13.git crypto/des: add an example to demonstrate EDE2 operation. EDE2 is a rare DES mode that can be implemented with crypto/des, but it's somewhat non-obvious so this CL adds an example of doing so. Fixes #3537. R=golang-dev, adg CC=golang-dev https://golang.org/cl/6721056 --- diff --git a/src/pkg/crypto/des/des_test.go b/src/pkg/crypto/des/des_test.go index e9fc236299..2e87e99b67 100644 --- a/src/pkg/crypto/des/des_test.go +++ b/src/pkg/crypto/des/des_test.go @@ -1503,3 +1503,21 @@ func TestSubstitutionTableKnownAnswerDecrypt(t *testing.T) { } } } + +func ExampleNewTripleDESCipher() { + // NewTripleDESCipher can also be used when EDE2 is required by + // duplicating the first 8 bytes of the 16-byte key. + ede2Key := []byte("example key 1234") + + var tripleDESKey []byte + tripleDESKey = append(tripleDESKey, ede2Key[:16]...) + tripleDESKey = append(tripleDESKey, ede2Key[:8]...) + + _, err := NewTripleDESCipher(tripleDESKey) + if err != nil { + panic(err) + } + + // See crypto/cipher for how to use a cipher.Block for encryption and + // decryption. +}