public class AESUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
CBC_CIPHER_ALGORITHM
AES的CBC加密算法
|
static String |
ECB_CIPHER_ALGORITHM
AES的ECB加密算法
|
static byte[] |
IVPARAMETERS
IV(Initialization Value)是一个初始值,对于CBC模式来说,它必须是随机选取并且需要保密的
而且它的长度和密码分组相同(比如:对于AES 128为128位,即长度为16的byte类型数组)
|
static String |
KEY_ALGORITHM
加密算法
|
| Constructor and Description |
|---|
AESUtils() |
| Modifier and Type | Method and Description |
|---|---|
static String |
decreptCBC(byte[] decodedText,
SecretKey key,
byte[] IVParameter)
CBC 解密
|
static byte[] |
decryptCTR(byte[] cipherBytes,
String key,
String counter) |
static String |
decryptECB(byte[] decodedText,
SecretKey key)
使用ECB解密
|
static byte[] |
encryptCBC(byte[] plainText,
SecretKey key,
byte[] IVParameter)
CBC加密
|
static byte[] |
encryptECB(byte[] plainText,
SecretKey key)
使用ECB模式进行加密。 加密过程三步走:
1.传入算法,实例化一个加解密器
2.传入加密模式和密钥,初始化一个加密器
3.调用doFinal方法加密
|
static byte[] |
generateAESSecretKey()
生成秘钥
1.创建一个KeyGenerator
2.调用KeyGenerator.generateKey方法
|
static void |
main(String[] arg) |
static SecretKey |
restoreSecretKey(byte[] secretBytes)
还原密钥
|
public static final String KEY_ALGORITHM
public static final String ECB_CIPHER_ALGORITHM
public static final String CBC_CIPHER_ALGORITHM
public static final byte[] IVPARAMETERS
public static byte[] encryptECB(byte[] plainText,
SecretKey key)
public static byte[] encryptCBC(byte[] plainText,
SecretKey key,
byte[] IVParameter)
public static String decreptCBC(byte[] decodedText, SecretKey key, byte[] IVParameter)
public static byte[] generateAESSecretKey()
public static SecretKey restoreSecretKey(byte[] secretBytes)
public static byte[] decryptCTR(byte[] cipherBytes,
String key,
String counter)
cipherBytes - 密文key - 秘钥counter - 初始化计数器public static void main(String[] arg)
Copyright © 2021. All rights reserved.