java中的aes加密演算法如下:
<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>
請問如何用php來實現
我測試了很多網上的例子都不能得到相同的密文
java中的aes加密演算法如下:
<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>
請問如何用php來實現
我測試了很多網上的例子都不能得到相同的密文
可能是編碼的問題,java預設是GBK編碼;
php編碼類型與頁面的保存編碼有關。