【发布时间】:2015-06-27 23:25:33
【问题描述】:
我正在尝试将加密数据从我的 android 应用程序发送到解密数据的 PHP 脚本。
在android中我使用以下加密方法:
public String encryptAES(String key, String mdp) throws NoSuchPaddingException, NoSuchAlgorithmException {
byte[] skey = key.getBytes();
byte[] pwd = mdp.getBytes();
byte[] encrypted = null;
SecretKeySpec secretKeySpec = new SecretKeySpec(skey, "AES");
Cipher cipher = Cipher.getInstance("AES");
try {
cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
} catch (InvalidKeyException e) {
e.printStackTrace();
}
try {
encrypted = cipher.doFinal(pwd);
} catch (IllegalBlockSizeException | BadPaddingException e) {
e.printStackTrace();
}
return Arrays.toString(Base64.encode(encrypted, Base64.DEFAULT));
}
我用它在 PHP 中解密:
$data = mcrypt_decrypt(MCRYPT_RIJNADEAL_128, $key, $cipherText, MCRYPT_MODE_ECB);
问题是它不能解密为 PHP 中想要的纯文本。
【问题讨论】:
标签: php android encryption encoding