public class CryptoUtil extends Object
| Constructor and Description |
|---|
CryptoUtil() |
| Modifier and Type | Method and Description |
|---|---|
static String |
aesDecrypt(byte[] input,
byte[] key)
使用AES解密字符串, 返回原始字符串.
|
static String |
aesDecrypt(byte[] input,
byte[] key,
byte[] iv)
使用AES解密字符串, 返回原始字符串.
|
static byte[] |
aesEncrypt(byte[] input,
byte[] key)
使用AES加密原始字符串.
|
static byte[] |
aesEncrypt(byte[] input,
byte[] key,
byte[] iv)
使用AES加密原始字符串.
|
static byte[] |
generateAesKey()
生成AES密钥,返回字节数组, 默认长度为128位(16字节).
|
static byte[] |
generateAesKey(int keysize)
生成AES密钥,可选长度为128,192,256位.
|
static byte[] |
generateHmacSha1Key()
生成HMAC-SHA1密钥,返回字节数组,长度为160位(20字节).
|
static byte[] |
generateIV()
生成随机向量,默认大小为cipher.getBlockSize(), 16字节.
|
static byte[] |
hmacSha1(byte[] input,
byte[] key)
使用HMAC-SHA1进行消息签名, 返回字节数组,长度为20字节.
|
static boolean |
isMacValid(byte[] expected,
byte[] input,
byte[] key)
校验HMAC-SHA1签名是否正确.
|
public static byte[] hmacSha1(byte[] input,
byte[] key)
input - 原始输入字符数组key - HMAC-SHA1密钥public static boolean isMacValid(byte[] expected,
byte[] input,
byte[] key)
expected - 已存在的签名input - 原始输入字符串key - 密钥public static byte[] generateHmacSha1Key()
public static byte[] aesEncrypt(byte[] input,
byte[] key)
input - 原始输入字符数组key - 符合AES要求的密钥public static byte[] aesEncrypt(byte[] input,
byte[] key,
byte[] iv)
input - 原始输入字符数组key - 符合AES要求的密钥iv - 初始向量public static String aesDecrypt(byte[] input, byte[] key)
input - Hex编码的加密字符串key - 符合AES要求的密钥public static String aesDecrypt(byte[] input, byte[] key, byte[] iv)
input - Hex编码的加密字符串key - 符合AES要求的密钥iv - 初始向量public static byte[] generateAesKey()
public static byte[] generateAesKey(int keysize)
public static byte[] generateIV()
Copyright © 2018. All rights reserved.