Closed sfter closed 1 year ago
Print the error
hexStr := "13863dbecd8078bf2c8d4a795fe203e4"
decrypt := dongle.Decrypt.FromHexString(str).ByAes(cipher)
fmt.Println(decrypt.Error)
<?php
$padding = OPENSSL_RAW_DATA;
$str = "483";
$key = "5953kdz0K4pG5fd32nEQfdka23M2fkwa";
$data = openssl_encrypt($str, 'AES-128-ECB', $key, $padding);
$data = strtolower(bin2hex($data));
echo $data;
echo "\r\n";
$decrypted = openssl_decrypt(hex2bin($data), 'AES-128-ECB', $key, $padding);
echo $decrypted;
echo "\r\n";
?>
php output: cbb287ca4ce7c8d84993044e2b33222a 483
func TestDecryptAes(t *testing.T) {
key := "5953kdz0K4pG5fd32nEQfdka23M2fkwa"
cipher := dongle.NewCipher()
// CBC、CFB、OFB、CTR、ECB
cipher.SetMode(dongle.ECB)
// No、Zero、PKCS5、PKCS7、AnsiX923、ISO97971
cipher.SetPadding(dongle.Zero)
// key 长度必须是 16、24 或 32 字节
cipher.SetKey(key)
// iv 长度必须是 16 字节,ECB 模式不需要设置 iv
//cipher.SetIV("")
str := "cbb287ca4ce7c8d84993044e2b33222a"
//str = dongle.Decode.FromString(str).ByHex().ToString()
str = dongle.Decrypt.FromHexString(str).ByAes(cipher).ToString()
println(str)
}
golang output: $״�&��@�0����z
There is no error message, but the result of Golang is inconsistent with that of Php.
Golang use padding with Zero, php should also use padding with OPENSSL_ZERO_PADDING
PHP OPENSSL_RAW_DATA be equal to dongle. No
In addition, NoPadding requires that the encrypted string must be multiple of 16
The following is the php implementation code
output: 13863dbecd8078bf2c8d4a795fe203e4 483
The following is the Go implementation code
output Empty string
But I can't decrypt with go. How can I decrypt with go?