mirror of
https://github.com/golang/go
synced 2024-10-14 03:43:28 +00:00
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
This commit is contained in:
parent
d324c4af87
commit
8f1d170fc6
|
@ -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.
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue