This commit is contained in:
2025-09-12 17:29:20 +08:00
parent 91be5bd1e8
commit e26e9f5978
4 changed files with 10 additions and 23 deletions

View File

@@ -9,19 +9,18 @@ import (
func TestAesEcbMobileEncryption(t *testing.T) {
// 测试手机号加密
mobile := "18653052547"
key := []byte("ff83609b2b24fc73196aac3d3dfb874f") // 16字节AES-128密钥
mobile := "18276151590"
key := "ff83609b2b24fc73196aac3d3dfb874f" // 16字节AES-128密钥
keyStr := hex.EncodeToString(key)
// 测试加密
encrypted, err := EncryptMobile(mobile, keyStr)
encrypted, err := EncryptMobile(mobile, key)
if err != nil {
t.Fatalf("手机号加密失败: %v", err)
}
fmt.Printf("encrypted: %s\n", encrypted)
jmStr := "m9EEeW9ZBBJmi1hx1k1uIQ=="
// 测试解密
decrypted, err := DecryptMobile(jmStr, keyStr)
decrypted, err := DecryptMobile(jmStr, key)
if err != nil {
t.Fatalf("手机号解密失败: %v", err)
}
@@ -32,7 +31,7 @@ func TestAesEcbMobileEncryption(t *testing.T) {
}
// 测试相同输入产生相同输出(确定性)
encrypted2, _ := EncryptMobile(mobile, keyStr)
encrypted2, _ := EncryptMobile(mobile, key)
if encrypted != encrypted2 {
t.Errorf("AES-ECB不是确定性的两次加密结果不同: %s vs %s", encrypted, encrypted2)
}