public class CryptoUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_AES_KEY_SIZE |
static int |
DEFAULT_IV_SIZE |
| 限定符和类型 | 方法和说明 |
|---|---|
static byte[] |
aesDecrypt(byte[] input,
byte[] key)
使用AES解密字符串, 返回原始字符串.
|
static byte[] |
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 String |
byte2hex(byte[] bytes)
把字节流转换为十六进制表示方式。
|
static String |
bytesToHexString(byte[] paramArrayOfByte) |
static byte |
charToByte(char paramChar) |
static byte[] |
encryptMD5(byte[] data)
对字节流进行MD5摘要。
|
static byte[] |
encryptMD5(String data)
对字符串采用UTF-8编码后,用MD5进行摘要。
|
static byte[] |
generateAesKey(int keysize)
生成AES密钥,可选长度为128,192,256位.
|
static byte[] |
generateIV()
生成随机向量,默认大小为cipher.getBlockSize(), 16字节.
|
static byte[] |
hexStringToBytes(String paramString) |
static String |
signRequest(Map<String,String> params,
String secret,
String signMethod)
给请求签名。
|
static String |
signRequest(Map<String,String> params,
String body,
String secret,
String signMethod)
给请求签名。
|
static String |
signRequest(String queryString,
String body,
String secret,
String signMethod)
给请求签名。
|
public static final int DEFAULT_AES_KEY_SIZE
public static final int DEFAULT_IV_SIZE
public static String signRequest(Map<String,String> params, String secret, String signMethod) throws IOException, GeneralSecurityException
params - 请求参数secret - 签名密钥signMethod - signMethod 签名方法IOException - the io exceptionGeneralSecurityException - the general security exceptionpublic static String signRequest(Map<String,String> params, String body, String secret, String signMethod) throws IOException, GeneralSecurityException
params - 请求参数body - 请求主体内容secret - 签名密钥signMethod - 签名方法IOException - the io exceptionGeneralSecurityException - the general security exceptionpublic static String signRequest(String queryString, String body, String secret, String signMethod) throws IOException, GeneralSecurityException
queryString - 请求参数body - 请求主体内容secret - 签名密钥signMethod - 签名方法IOException - the io exceptionGeneralSecurityException - the general security exceptionpublic static byte[] encryptMD5(String data) throws IOException, GeneralSecurityException
data - the dataIOException - the io exceptionGeneralSecurityException - the general security exceptionpublic static byte[] encryptMD5(byte[] data)
throws IOException,
GeneralSecurityException
data - the dataIOException - the io exceptionGeneralSecurityException - the general security exceptionpublic static String byte2hex(byte[] bytes)
bytes - the bytespublic 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 byte[] aesDecrypt(byte[] input,
byte[] key)
input - base64编码的加密字符串key - 符合AES要求的密钥public static byte[] aesDecrypt(byte[] input,
byte[] key,
byte[] iv)
input - base64编码的加密字符串key - 符合AES要求的密钥iv - 初始向量public static byte[] generateAesKey(int keysize)
keysize - the keysizepublic static byte[] generateIV()
public static String bytesToHexString(byte[] paramArrayOfByte)
public static byte[] hexStringToBytes(String paramString)
public static byte charToByte(char paramChar)
Copyright © 2022. All rights reserved.