import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
/**
* AES加密器
*
* @author Eric_Ni
*
*/
public class AESEncryptor {
/**
* AES加密
*/
public static String encrypt(String seed, String cleartext)
throws Exception {
byte[] rawKey = getRawKey(seed.getBytes());
byte[] result = encrypt(rawKey, cleartext.getBytes());
return toHex(result);
}
/**
* AES解密
*/
public static String decrypt(String seed, String encrypted)
throws Exception {
if (seed == null || "".equals(seed) || encrypted == null || "".equals(encrypted)){
return null;
}
byte[] rawKey = getRawKey(seed.getBytes());
byte[] enc = toByte(encrypted);
byte[] result = decrypt(rawKey, enc);
return new String(result);
}
private static byte[] getRawKey(byte
【工具类】AES加密和解密
最新推荐文章于 2024-01-15 09:52:39 发布
本文详细介绍了AES加密算法的原理与应用,通过实例演示如何在编程中实现AES的加密和解密过程,适用于数据安全保护场景。
摘要由CSDN通过智能技术生成