完善其他类型的加解密
This commit is contained in:
+89
-8
@@ -7,7 +7,7 @@ import (
|
||||
"code.yun.ink/pkg/encryptx/aesx"
|
||||
)
|
||||
|
||||
func TestAes(t *testing.T) {
|
||||
func TestGCM(t *testing.T) {
|
||||
key := "example key 1234"
|
||||
plaintext := "exampleplaintext"
|
||||
|
||||
@@ -21,16 +21,97 @@ func TestAes(t *testing.T) {
|
||||
fmt.Println(plaintext, err)
|
||||
///GCM
|
||||
noncetext := ""
|
||||
ciphertext, noncetext, err = aesx.AESGCMEncrypt(key, plaintext)
|
||||
ciphertext, noncetext, err = aesx.EncryptGCM(key, plaintext)
|
||||
fmt.Println(ciphertext, err)
|
||||
|
||||
plaintext, err = aesx.AESGCMDecrypter(key, ciphertext, noncetext)
|
||||
plaintext, err = aesx.DecryptGCM(key, ciphertext, noncetext)
|
||||
fmt.Println(plaintext, err)
|
||||
}
|
||||
|
||||
func TestDemo(t *testing.T) {
|
||||
c := []byte("08I2GfoqfIlUYgteelimxQ")
|
||||
c := []byte("rRq++jXDMPDVcUkXAZA9kg==:o57DgQ+iQMXpERuShWs/XA==")
|
||||
a,e := aesx.AesDecrypt(c, k)
|
||||
fmt.Println(a,e)
|
||||
func TestECB(t *testing.T) {
|
||||
key := "example key 1234"
|
||||
plaintext := "exampleplaintext"
|
||||
|
||||
// 测试ECB加密和解密
|
||||
encrypted, err := aesx.EncryptECBHex(plaintext, key)
|
||||
if err != nil {
|
||||
t.Fatalf("ECB加密失败: %v", err)
|
||||
}
|
||||
fmt.Printf("ECB加密结果: %s\n", encrypted)
|
||||
|
||||
decrypted, err := aesx.DecryptECBHex(encrypted, key)
|
||||
if err != nil {
|
||||
t.Fatalf("ECB解密失败: %v", err)
|
||||
}
|
||||
fmt.Printf("ECB解密结果: %s\n", decrypted)
|
||||
|
||||
if decrypted != plaintext {
|
||||
t.Fatalf("ECB解密结果不匹配,原文: %s, 解密结果: %s", plaintext, decrypted)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCBC(t *testing.T) {
|
||||
key := "example key 1234"
|
||||
plaintext := "exampleplaintext"
|
||||
|
||||
// 测试CBC加密和解密
|
||||
encrypted, err := aesx.EncryptCBCHex(plaintext, key)
|
||||
if err != nil {
|
||||
t.Fatalf("CBC加密失败: %v", err)
|
||||
}
|
||||
fmt.Printf("CBC加密结果: %s\n", encrypted)
|
||||
|
||||
decrypted, err := aesx.DecryptCBCHex(encrypted, key)
|
||||
if err != nil {
|
||||
t.Fatalf("CBC解密失败: %v", err)
|
||||
}
|
||||
fmt.Printf("CBC解密结果: %s\n", decrypted)
|
||||
|
||||
if decrypted != plaintext {
|
||||
t.Fatalf("CBC解密结果不匹配,原文: %s, 解密结果: %s", plaintext, decrypted)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCFB(t *testing.T) {
|
||||
key := "example key 1234"
|
||||
plaintext := "exampleplaintext"
|
||||
|
||||
// 测试CFB加密和解密
|
||||
encrypted, err := aesx.EncryptCFBHex(plaintext, key)
|
||||
if err != nil {
|
||||
t.Fatalf("CFB加密失败: %v", err)
|
||||
}
|
||||
fmt.Printf("CFB加密结果: %s\n", encrypted)
|
||||
|
||||
decrypted, err := aesx.DecryptCFBHex(encrypted, key)
|
||||
if err != nil {
|
||||
t.Fatalf("CFB解密失败: %v", err)
|
||||
}
|
||||
fmt.Printf("CFB解密结果: %s\n", decrypted)
|
||||
|
||||
if decrypted != plaintext {
|
||||
t.Fatalf("CFB解密结果不匹配,原文: %s, 解密结果: %s", plaintext, decrypted)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOFB(t *testing.T) {
|
||||
key := "example key 1234"
|
||||
plaintext := "exampleplaintext"
|
||||
|
||||
// 测试OFB加密和解密
|
||||
encrypted, err := aesx.EncryptOFBHex(plaintext, key)
|
||||
if err != nil {
|
||||
t.Fatalf("OFB加密失败: %v", err)
|
||||
}
|
||||
fmt.Printf("OFB加密结果: %s\n", encrypted)
|
||||
|
||||
decrypted, err := aesx.DecryptOFBHex(encrypted, key)
|
||||
if err != nil {
|
||||
t.Fatalf("OFB解密失败: %v", err)
|
||||
}
|
||||
fmt.Printf("OFB解密结果: %s\n", decrypted)
|
||||
|
||||
if decrypted != plaintext {
|
||||
t.Fatalf("OFB解密结果不匹配,原文: %s, 解密结果: %s", plaintext, decrypted)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user