fix promotion

This commit is contained in:
2025-06-20 15:11:38 +08:00
parent 97e50d11d6
commit 3c3037a049
3 changed files with 29 additions and 11 deletions

View File

@@ -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)
}