| 1 | package aes |
| 2 | |
| 3 | import ( |
| 4 | // "fmt" |
| 5 | "crypto/aes" |
| 6 | // "crypto/cipher" |
| 7 | . "gopkg.in/check.v1" |
| 8 | ) |
| 9 | |
| 10 | func (s *TestSuite) TestNewECBEncryptor(c *C) { |
| 11 | //given |
| 12 | plaintext := []byte{0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255} |
| 13 | kek := []byte{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} |
| 14 | block, _ := aes.NewCipher(kek) |
| 15 | |
| 16 | test := make([]byte,len(plaintext)) |
| 17 | |
| 18 | //when |
| 19 | NewECBEncrypter(block).CryptBlocks(test,plaintext) |
| 20 | |
| 21 | //then |
| 22 | c.Assert(test, DeepEquals, []byte{105,196,224,216,106,123,4,48,216,205,183,128,112,180,197,90}) |
| 23 | } |
| 24 | |
| 25 | func (s *TestSuite) TestNewECBDecryptor(c *C) { |
| 26 | //given |
| 27 | ciphertext := []byte{105,196,224,216,106,123,4,48,216,205,183,128,112,180,197,90} |
| 28 | kek := []byte{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} |
| 29 | block, _ := aes.NewCipher(kek) |
| 30 | |
| 31 | test := make([]byte,len(ciphertext)) |
| 32 | |
| 33 | //when |
| 34 | NewECBDecrypter(block).CryptBlocks(test,ciphertext) |
| 35 | |
| 36 | //then |
| 37 | c.Assert(test, DeepEquals, []byte{0, 17, 34, 51, 68, 85, 102, 119, 136, 153, 170, 187, 204, 221, 238, 255}) |
| 38 | } |