这个是java的解密代码
private static final String IV = "ZZXJoOLvoTJ5u2BF";
private static final String KEY_ALGORITHM = "AES";
public static final String UTF_8 = "UTF-8";
public static final String AES_CBC_PADDING = "AES/CBC/PKCS5Padding";
public static String decrypt(String data, String key) throws Exception {
return new String(decrypt(Base64.decodeBase64(data), Base64.decodeBase64(key)), "UTF-8");
}
private static byte[] decrypt(byte[] data, byte[] key) throws Exception{
Key k = new SecretKeySpec(key, KEY_ALGORITHM);
IvParameterSpec iv = new IvParameterSpec(IV.getBytes());
Cipher cipher = Cipher.getInstance(AES_CBC_PADDING);
cipher.init(Cipher.DECRYPT_MODE, k, iv);
return cipher.doFinal(data);
}
php 该如何加密呢?
问题也许在于你用的 base64 编码,byte[] 转字符串或字符串转 byte[] 时。如果这样,PHP 也要同等用 base64 endcode/decode。PHP 方面注意
OPENSSL_ZERO_PADDING/OPENSSL_RAW_DATA
模式。