-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathecb_test.go
More file actions
51 lines (40 loc) · 1.25 KB
/
ecb_test.go
File metadata and controls
51 lines (40 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package openssl
import (
"crypto/aes"
"testing"
"github.com/stretchr/testify/assert"
)
func TestECBEncryptAndDecrypt(t *testing.T) {
key := []byte("12345678901234567890123456789012") // 32 bytes for AES-256
block, err := aes.NewCipher(key)
assert.NoError(t, err)
src := []byte("test data")
// Test encryption
encrypted, err := ECBEncrypt(block, src, PKCS7_PADDING)
assert.NoError(t, err)
assert.NotEmpty(t, encrypted)
// Test decryption
decrypted, err := ECBDecrypt(block, encrypted, PKCS7_PADDING)
assert.NoError(t, err)
assert.Equal(t, src, decrypted)
}
func TestECBEncrypterCryptBlocks(t *testing.T) {
key := []byte("1234567890123456") // 16 bytes for AES-128
block, err := aes.NewCipher(key)
assert.NoError(t, err)
encrypter := NewECBEncrypter(block)
src := make([]byte, encrypter.BlockSize()*2)
dst := make([]byte, len(src))
encrypter.CryptBlocks(dst, src)
assert.Equal(t, len(src), len(dst))
}
func TestECBDecrypterCryptBlocks(t *testing.T) {
key := []byte("1234567890123456") // 16 bytes for AES-128
block, err := aes.NewCipher(key)
assert.NoError(t, err)
decrypter := NewECBDecrypter(block)
src := make([]byte, decrypter.BlockSize()*2)
dst := make([]byte, len(src))
decrypter.CryptBlocks(dst, src)
assert.Equal(t, len(src), len(dst))
}