The aes encryption algorithm in java is as follows:
<code> public static byte[] decrypt(byte[] data, byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { Security.addProvider(new BouncyCastleProvider()); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding"); cipher.init(2, new SecretKeySpec(key, "AES")); return cipher.doFinal(data); } public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { Security.addProvider(new BouncyCastleProvider()); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding"); cipher.init(1, new SecretKeySpec(key, "AES")); return cipher.doFinal(data); }</code>
Please tell me how to use php to achieve it
I have tested many online examples but cannot get the same ciphertext
The aes encryption algorithm in java is as follows:
<code> public static byte[] decrypt(byte[] data, byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { Security.addProvider(new BouncyCastleProvider()); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding"); cipher.init(2, new SecretKeySpec(key, "AES")); return cipher.doFinal(data); } public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException { Security.addProvider(new BouncyCastleProvider()); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding"); cipher.init(1, new SecretKeySpec(key, "AES")); return cipher.doFinal(data); }</code>
Please tell me how to use php to achieve this
I have tested many online examples but cannot get the same ciphertext
It may be an encoding problem. Java defaults to GBK encoding;
The php encoding type is related to the page's saving encoding.