public class AesUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
AES
算法
|
static String |
CHARSET_NAME
编码
|
static String |
CIPHER_MODE_CBC_PKCS5PADDING |
static String |
CIPHER_MODE_ECB_PKCS5PADDING
算法:AES/加密模式:ECB/填充方式:PKCS5Padding
默认:AES/ECB/PKCS5Padding
ECB模式不支持向量
|
static String |
CIPHER_MODE_ECB_PKCS7PADDING |
static int |
KEY_SIZE_128
生成密钥的长度
|
static int |
KEY_SIZE_192 |
static int |
KEY_SIZE_256 |
| 构造器和说明 |
|---|
AesUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
decodeBase64(String content,
String pwdKey)
base64解密后aes解密
|
static String |
decodeBase64(String content,
String pwdKey,
byte[] iv,
String transformMode)
base64解密后aes解密
|
static byte[] |
decrypt(byte[] content,
String pwdKey)
解密
|
static byte[] |
decryptByIv(byte[] content,
String pwdKey,
byte[] iv,
String transformMode)
解密
|
static String |
encodeBase64(String content,
String pwdKey)
base64 加密后aes加密
|
static String |
encodeBase64(String content,
String pwdKey,
byte[] iv,
String transformMode)
base64 加密后aes加密
|
static byte[] |
encrypt(String content,
String pwdKey)
加密
|
static byte[] |
encryptByIv(String content,
String pwdKey,
byte[] iv,
String transformMode)
加密
|
static String |
generateSecret(int keySize)
生成随机密钥
|
static void |
main(String[] args) |
public static final String CIPHER_MODE_ECB_PKCS5PADDING
public static final int KEY_SIZE_128
public static final int KEY_SIZE_192
public static final int KEY_SIZE_256
public static String generateSecret(int keySize)
keySize - 密钥大小: 128 192 256
128 返回16位key
192 返回24位key
256 返回32位keypublic static byte[] encrypt(String content, String pwdKey) throws GeneralSecurityException, UnsupportedEncodingException
content - 需要加密的字符串pwdKey - 密钥GeneralSecurityException - errorUnsupportedEncodingException - errpublic static byte[] encryptByIv(String content, String pwdKey, byte[] iv, String transformMode) throws GeneralSecurityException, UnsupportedEncodingException
content - 需要加密的字符串pwdKey - 密钥iv - 向量transformMode - 加密模式GeneralSecurityException - errorUnsupportedEncodingException - errpublic static String encodeBase64(String content, String pwdKey) throws GeneralSecurityException, UnsupportedEncodingException
content - 内容pwdKey - 密钥GeneralSecurityException - errUnsupportedEncodingException - errpublic static String encodeBase64(String content, String pwdKey, byte[] iv, String transformMode) throws GeneralSecurityException, UnsupportedEncodingException
content - 内容pwdKey - 密钥iv - 向量transformMode - 加密模式GeneralSecurityException - errUnsupportedEncodingException - errpublic static byte[] decrypt(byte[] content,
String pwdKey)
throws GeneralSecurityException,
UnsupportedEncodingException
content - 需要解密的字符串pwdKey - 密钥GeneralSecurityExceptionUnsupportedEncodingExceptionpublic static byte[] decryptByIv(byte[] content,
String pwdKey,
byte[] iv,
String transformMode)
throws GeneralSecurityException,
UnsupportedEncodingException
content - 需要解密的字符串pwdKey - 密钥iv - 向量transformMode - 加密模式GeneralSecurityExceptionUnsupportedEncodingExceptionpublic static String decodeBase64(String content, String pwdKey) throws GeneralSecurityException, UnsupportedEncodingException
content - 内容pwdKey - 密钥GeneralSecurityException - errorUnsupportedEncodingException - errpublic static String decodeBase64(String content, String pwdKey, byte[] iv, String transformMode) throws GeneralSecurityException, UnsupportedEncodingException
content - 内容pwdKey - 密钥iv - 向量transformMode - 加密模式GeneralSecurityException - errorUnsupportedEncodingException - errCopyright © 2020. All rights reserved.