用java代码实现一个AES加密代码
时间: 2023-03-15 22:11:53 浏览: 108
java使用RSA与AES加密解密的实例代码详解
我可以为您提供一份示例代码来实现AES加密:import javax.crypto.Cipher;import javax.crypto.spec.SecretKeySpec;public class AES {public static byte[] encrypt(String plainText, String key) throws Exception{SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), "AES");Cipher cipher = Cipher.getInstance("AES");cipher.init(Cipher.ENCRYPT_MODE, secretKey);return cipher.doFinal(plainText.getBytes());}public static byte[] decrypt(byte[] cipherText, String key) throws Exception{SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), "AES");Cipher cipher = Cipher.getInstance("AES");cipher.init(Cipher.DECRYPT_MODE, secretKey);return cipher.doFinal(cipherText);}}
阅读全文