-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaes_test.go
More file actions
91 lines (75 loc) · 3.81 KB
/
Copy pathaes_test.go
File metadata and controls
91 lines (75 loc) · 3.81 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package xutil
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
func TestAESEncryptCBC(t *testing.T) {
a := assert.New(t)
plain := "Hello, playground"
key128 := "abcdefghijklmnop" // 16 bytes = 128 bits
key192 := "abcdefghijklmnopqrstuvwx" // 24 bytes = 192 bits
key256 := "abcdefghijklmnopabcdefghijklmnop" // 32 bytes = 256 bits
ivInfo := "abcdefghijklmnop"
cipherText128, _ := AESEncrypt(plain, AESModeCBC, key128, ivInfo)
fmt.Printf("Cipher text for AES-128-CBC: %s\n", cipherText128)
cipherText192, _ := AESEncrypt(plain, AESModeCBC, key192, ivInfo)
fmt.Printf("Cipher text for AES-192-CBC: %s\n", cipherText192)
cipherText256, _ := AESEncrypt(plain, AESModeCBC, key256, ivInfo)
fmt.Printf("Cipher text for AES-256-CBC: %s\n", cipherText256)
decryptedText128, _ := AESDecrypt(cipherText128, AESModeCBC, key128, ivInfo)
fmt.Printf("Decrypted text for AES-128-CBC: %s\n", decryptedText128)
decryptedText192, _ := AESDecrypt(cipherText192, AESModeCBC, key192, ivInfo)
fmt.Printf("Decrypted text for AES-192-CBC: %s\n", decryptedText192)
decryptedText256, _ := AESDecrypt(cipherText256, AESModeCBC, key256, ivInfo)
fmt.Printf("Decrypted text for AES-256-CBC: %s\n", decryptedText256)
a.Equal(plain, decryptedText128)
a.Equal(plain, decryptedText192)
a.Equal(plain, decryptedText256)
}
func TestAESEncryptCFB(t *testing.T) {
a := assert.New(t)
plain := "Hello, playground"
key128 := "abcdefghijklmnop" // 16 bytes = 128 bits
key192 := "abcdefghijklmnopqrstuvwx" // 24 bytes = 192 bits
key256 := "abcdefghijklmnopabcdefghijklmnop" // 32 bytes = 256 bits
ivInfo := "abcdefghijklmnop"
cipherText128, _ := AESEncrypt(plain, AESModeCFB, key128, ivInfo)
fmt.Printf("Cipher text for AES-128-CBC: %s\n", cipherText128)
cipherText192, _ := AESEncrypt(plain, AESModeCFB, key192, ivInfo)
fmt.Printf("Cipher text for AES-192-CBC: %s\n", cipherText192)
cipherText256, _ := AESEncrypt(plain, AESModeCFB, key256, ivInfo)
fmt.Printf("Cipher text for AES-256-CBC: %s\n", cipherText256)
decryptedText128, _ := AESDecrypt(cipherText128, AESModeCFB, key128, ivInfo)
fmt.Printf("Decrypted text for AES-128-CBC: %s\n", decryptedText128)
decryptedText192, _ := AESDecrypt(cipherText192, AESModeCFB, key192, ivInfo)
fmt.Printf("Decrypted text for AES-192-CBC: %s\n", decryptedText192)
decryptedText256, _ := AESDecrypt(cipherText256, AESModeCFB, key256, ivInfo)
fmt.Printf("Decrypted text for AES-256-CBC: %s\n", decryptedText256)
a.Equal(plain, decryptedText128)
a.Equal(plain, decryptedText192)
a.Equal(plain, decryptedText256)
}
func TestAESEncryptOFB(t *testing.T) {
a := assert.New(t)
plain := "Hello, playground"
key128 := "abcdefghijklmnop" // 16 bytes = 128 bits
key192 := "abcdefghijklmnopqrstuvwx" // 24 bytes = 192 bits
key256 := "abcdefghijklmnopabcdefghijklmnop" // 32 bytes = 256 bits
ivInfo := "abcdefghijklmnop"
cipherText128, _ := AESEncrypt(plain, AESModeOFB, key128, ivInfo)
fmt.Printf("Cipher text for AES-128-CBC: %s\n", cipherText128)
cipherText192, _ := AESEncrypt(plain, AESModeOFB, key192, ivInfo)
fmt.Printf("Cipher text for AES-192-CBC: %s\n", cipherText192)
cipherText256, _ := AESEncrypt(plain, AESModeOFB, key256, ivInfo)
fmt.Printf("Cipher text for AES-256-CBC: %s\n", cipherText256)
decryptedText128, _ := AESDecrypt(cipherText128, AESModeOFB, key128, ivInfo)
fmt.Printf("Decrypted text for AES-128-CBC: %s\n", decryptedText128)
decryptedText192, _ := AESDecrypt(cipherText192, AESModeOFB, key192, ivInfo)
fmt.Printf("Decrypted text for AES-192-CBC: %s\n", decryptedText192)
decryptedText256, _ := AESDecrypt(cipherText256, AESModeOFB, key256, ivInfo)
fmt.Printf("Decrypted text for AES-256-CBC: %s\n", decryptedText256)
a.Equal(plain, decryptedText128)
a.Equal(plain, decryptedText192)
a.Equal(plain, decryptedText256)
}