我具有以下VB函数,该函数接收以下参数:
输入:145145
通过:CeMdGrTeV6BtrEg0p8sUMg ==
并返回字符串:KT8uZ9nlacOFBfg1nPY + zA ==
我试图将各个步骤转换为php,但我无法获得相同的输出,有人知道我该怎么做?
Public Function AES_Encrypt(ByVal input As String, ByVal pass As String) As String
Dim AES As New System.Security.Cryptography.RijndaelManaged
Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim encrypted As String = ""
Try
Dim hash(31) As Byte
Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
Array.Copy(temp, 0, hash, 0, 16)
Array.Copy(temp, 0, hash, 15, 16)
AES.Key = hash
AES.Mode = Security.Cryptography.CipherMode.ECB
Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor
Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input)
encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
Return encrypted
Catch ex As Exception
Return ""
End Try
End Function
答案 0 :(得分:0)
我解决了!
private function AES_Encrypt($sValue, $sSecretKey)
{
$cipher = 'AES-256-ECB';
$plaintext = $sValue;
$key = $sSecretKey;
$key = base64_encode(md5(mb_convert_encoding($key, "UCS-2LE", "JIS, eucjp-win, sjis-win"), true));
$keyBytes = md5($key, true);
for($i = 0; $i < mb_strlen($keyBytes, 'ASCII'); $i++) {
$temp1[] = $keyBytes[$i];
}
$temp2 = $temp1;
unset($temp1[count($temp1)-1]);
$temp3 = array_merge($temp1,$temp2);
$key = implode('',$temp3);
$enc = openssl_encrypt($plaintext, $cipher, $key, $options = 0);
return $enc;
}