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 用visual studi code完成html页面
    • ¥15 聚类分析或者python进行数据分析
    • ¥15 逻辑谓词和消解原理的运用
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?