dpndp64206 2015-10-27 23:43
浏览 65

Android Java和PHP加密(AES)不匹配

So I have this line of code:

$signature = openssl_decrypt(base64_decode($signature), 'AES-256-CBC', $apiKey->private_key, 0, $iv);

And in my Android application I have this:

public String encrypt(String message, String privateKey) throws Exception{
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    IvParameterSpec iv = makeIv();
    cipher.init(Cipher.ENCRYPT_MODE, makeKey(privateKey), iv);
    return Base64.encodeToString(cipher.doFinal(message.getBytes()), Base64.DEFAULT);
}

And when I encrypt something in Java and send it to PHP, there, I get different output from decryption following with signature check failure.

What is the right way to encrypt on Java/Android side so that I can decrypt it in PHP like the line above shows?

Note: Do not worry about IV as I have a mechanism of exchanging it so I am using the same one for encryption and decryption.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Python报错怎么解决
    • ¥15 simulink如何调用DLL文件
    • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
    • ¥30 线性代数的问题,我真的忘了线代的知识了
    • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
    • ¥188 需要修改一个工具,懂得汇编的人来。
    • ¥15 livecharts wpf piechart 属性
    • ¥20 数学建模,尽量用matlab回答,论文格式
    • ¥15 昨天挂载了一下u盘,然后拔了
    • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题