目前我正致力于在VB.NET中编写外部服务的集成。 这个服务发给我一个字符串,其中包含一些用下面的函数加密的信息(这是外部服务开发人员向我发送代码的剪切和过去)
Public Function Decode(ByVal S As String, ByVal chiave As String, ByVal iv As String) As String
Dim rjm As RijndaelManaged = New RijndaelManaged
rjm.KeySize = 128
rjm.BlockSize = 128
rjm.Key = System.Text.ASCIIEncoding.ASCII.GetBytes(chiave)
rjm.IV = System.Text.ASCIIEncoding.ASCII.GetBytes(iv)
Try
Dim input() As Byte = System.Convert.FromBase64String(S)
Dim output() As Byte = rjm.CreateDecryptor.TransformFinalBlock(input, 0, input.Length)
Return System.Text.Encoding.UTF8.GetString(output)
Catch ex As System.Exception
Return S
End Try
End Function
如果我使用下面的mcrypt函数解码字符串,一切都按预期工作:
$mcrypt_cipher = MCRYPT_RIJNDAEL_128;
$mcrypt_mode = MCRYPT_MODE_CBC;
$iv= '1234567891011121';
$key = '1234567891011121';
$message= base64_decode($message);
$message = rtrim(mcrypt_decrypt($mcrypt_cipher, $key, $message, $mcrypt_mode, $iv), "\0");;
但是我无法用openssl_decrypt获得相同的结果。在代码下面,函数总是以false结果失败:
$result = openssl_decrypt(
base64_decode($message),
'AES-128-CBC',
$key,
OPENSSL_RAW_DATA,
$iv
);
我很确定这个问题与我遗漏的一些填充有关..但我不明白问题究竟在哪里。
UPDATE1 - 我更正了代码,$ iv和$ key都是字符串我忘记了'两者都是16Bytes = 128Bits