import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.util.Base64;
/**
* AES工具类
*
**/
public class AESUtil {
/**
* 加密
*/
public static String encrypt(String secretKey, String content) {
try {
IvParameterSpec iv = new IvParameterSpec("FNQpwniuEaEriDDP".getBytes(StandardCharsets.UTF_8));
SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv);
byte[] bytes = cipher.doFinal(content.getBytes(StandardCharsets.UTF_8));
return Base64.getEncoder().encodeToString(bytes);
} catch (Exception e) {
e.printStackTrace();
AES加解密工具类(JDK)
最新推荐文章于 2024-06-18 19:00:00 发布