fix promotion
This commit is contained in:
@@ -9,29 +9,26 @@ import (
|
||||
|
||||
func TestAesEcbMobileEncryption(t *testing.T) {
|
||||
// 测试手机号加密
|
||||
mobile := "13800138000"
|
||||
key := []byte("1234567890abcdef") // 16字节AES-128密钥
|
||||
|
||||
keyStr := hex.EncodeToString(key)
|
||||
mobile := "13380082033"
|
||||
// 测试加密
|
||||
encrypted, err := EncryptMobile(mobile, keyStr)
|
||||
encrypted, err := EncryptMobile(mobile, "ff83609b2b24fc73196aac3d3dfb874f")
|
||||
if err != nil {
|
||||
t.Fatalf("手机号加密失败: %v", err)
|
||||
}
|
||||
fmt.Println(encrypted)
|
||||
fmt.Printf("encrypted: %s\n", encrypted)
|
||||
// 测试解密
|
||||
decrypted, err := DecryptMobile(encrypted, keyStr)
|
||||
decrypted, err := DecryptMobile("oEpLcrIpDPN63rOlESXTDg==", "ff83609b2b24fc73196aac3d3dfb874f")
|
||||
if err != nil {
|
||||
t.Fatalf("手机号解密失败: %v", err)
|
||||
}
|
||||
fmt.Println(decrypted)
|
||||
fmt.Printf("decrypted: %s\n", decrypted)
|
||||
// 验证结果
|
||||
if decrypted != mobile {
|
||||
t.Errorf("解密结果不匹配,期望: %s, 实际: %s", mobile, decrypted)
|
||||
}
|
||||
|
||||
// 测试相同输入产生相同输出(确定性)
|
||||
encrypted2, _ := EncryptMobile(mobile, keyStr)
|
||||
encrypted2, _ := EncryptMobile(mobile, "ff83609b2b24fc73196aac3d3dfb874f")
|
||||
if encrypted != encrypted2 {
|
||||
t.Errorf("AES-ECB不是确定性的,两次加密结果不同: %s vs %s", encrypted, encrypted2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user