java aes解密转化为php问题
java解密如下
public static void main(String[] args) throws Exception {
// 密钥
String base64EncodedKey = "xxxxxxxxxxxxx=";
SecretKey secretKey = new SecretKeySpec(Base64.getDecoder().decode(base64EncodedKey), "AES");
// 加密后的数据
String base64EncryptedData = "xxxxxxxxxxxxxxxx=";
// 解密数据
String decryptedData = decrypt(base64EncryptedData, secretKey);
// 输出结果
System.out.println("Decrypted Data: " + decryptedData);
}
// 使用AES解密数据
private static String decrypt(String base64EncryptedData, SecretKey secretKey) throws Exception {
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byte[] encryptedData = Base64.getDecoder().decode(base64EncryptedData);
byte[] decryptedBytes = cipher.doFinal(encryptedData);
return new String(decryptedBytes);
}
想请教下这个用php该怎么解密,我用的是如下代码,不对,java中secretKey做了什么处理呢,我decode是乱码
$decryptedData = openssl_decrypt(base64_decode($base64EncryptedData), 'AES-128-ECB', base64_decode($base64EncodedKey))
问答:PHP 使用 openssl 解密 java AES 加密的问题 可以看这个,然后pkcs5就是php的pkcs7补码,解码后去掉补码