duan20145 2018-06-05 12:56
浏览 98

使用openssl_decrypt将VB.NET AES编码转换为PHP

Currently I'm working on integration of external service wrote in VB.NET. This service send me a string with some information encrypted with below function (this is a cut and past from the external service developer that send me the code)

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

if I decode the string with below mcrypt function everything work as expected:

 $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");;

But i'm unable to obtain same result with openssl_decrypt. the function always fail with false as result, below the code:

 $result = openssl_decrypt(
                base64_decode($message),
                'AES-128-CBC',
                $key,
                OPENSSL_RAW_DATA,
                $iv
            );

I'm pretty sure that the problem is related to some padding that i missing.. but I don't understand where the problem is exactly.

UPDATE1 - I correct the code, both $iv and $key are strings i forgot the ' both are of 16Bytes = 128Bits

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
    • ¥15 安装svn网络有问题怎么办