-
Notifications
You must be signed in to change notification settings - Fork 2
/
crypt_test.go
35 lines (30 loc) · 1.3 KB
/
crypt_test.go
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
package crypt
import (
"encoding/base64"
"encoding/hex"
"log"
"testing"
)
func Test(t *testing.T) { // rename function
origData := []byte("xxxx-19981001-xxxx") // 待加密的数据
key := []byte("ABCDEFGHIJKLMNOP") // 加密的密钥
log.Println("原文:", string(origData))
log.Println("------------------ CBC模式 --------------------")
encrypted := AesEncryptCBC(origData, key)
log.Println("密文(hex):", hex.EncodeToString(encrypted))
log.Println("密文(base64):", base64.StdEncoding.EncodeToString(encrypted))
decrypted := AesDecryptCBC(encrypted, key)
log.Println("解密结果:", string(decrypted))
log.Println("------------------ ECB模式 --------------------")
encrypted = AesEncryptECB(origData, key)
log.Println("密文(hex):", hex.EncodeToString(encrypted))
log.Println("密文(base64):", base64.StdEncoding.EncodeToString(encrypted))
decrypted = AesDecryptECB(encrypted, key)
log.Println("解密结果:", string(decrypted))
log.Println("------------------ CFB模式 --------------------")
encrypted = AesEncryptCFB(origData, key)
log.Println("密文(hex):", hex.EncodeToString(encrypted))
log.Println("密文(base64):", base64.StdEncoding.EncodeToString(encrypted))
decrypted = AesDecryptCFB(encrypted, key)
log.Println("解密结果:", string(decrypted))
}