public class EncryptionUtils extends Object
| 构造器和说明 |
|---|
EncryptionUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
aesDecrypt(String content,
String key,
String iv)
AES解密
|
static String |
aesEncrypt(String content,
String key,
String iv)
AES加密
|
static KeyPair |
getKeyPair()
生成密钥对:密钥对中包含公钥和私钥
|
static String |
getPrivateKey(KeyPair keyPair)
获取私钥(并进行Base64编码,返回一个 Base64 编码后的字符串)
|
static String |
getPublicKey(KeyPair keyPair)
获取公钥 (并进行Base64编码,返回一个 Base64 编码后的字符串)
|
static String |
hMACSHA256(String data,
String key)
生成 HMACSHA256
|
static String |
md5(String data,
String salt,
boolean isUpper)
生成 MD5
|
static byte[] |
privateDecrypt(byte[] content,
PrivateKey privateKey)
私钥解密
|
static byte[] |
publicEncryType(byte[] content,
PublicKey publicKey)
公钥加密
|
static PrivateKey |
string2PrivateKey(String priStr)
将Base64编码后的私钥转换成 PrivateKey 对象
|
static PublicKey |
string2PublicKey(String pubStr)
将Base64编码后的公钥转换成 PublicKey 对象
|
public static String md5(String data, String salt, boolean isUpper)
data - salt - isUpper - public static String hMACSHA256(String data, String key) throws Exception
data - 待处理数据key - 密钥Exceptionpublic static String aesDecrypt(String content, String key, String iv) throws Exception
content - 待加密内容Exception - 异常public static String aesEncrypt(String content, String key, String iv) throws Exception
content - 待解密的内容Exception - 异常public static KeyPair getKeyPair() throws NoSuchAlgorithmException
NoSuchAlgorithmExceptionpublic static String getPublicKey(KeyPair keyPair)
keyPair - public static String getPrivateKey(KeyPair keyPair)
keyPair - public static PublicKey string2PublicKey(String pubStr) throws NoSuchAlgorithmException, InvalidKeySpecException
pubStr - NoSuchAlgorithmExceptionInvalidKeySpecExceptionpublic static PrivateKey string2PrivateKey(String priStr) throws NoSuchAlgorithmException, InvalidKeySpecException
priStr - NoSuchAlgorithmExceptionInvalidKeySpecExceptionpublic static byte[] publicEncryType(byte[] content,
PublicKey publicKey)
throws NoSuchPaddingException,
NoSuchAlgorithmException,
InvalidKeyException,
BadPaddingException,
IllegalBlockSizeException
content - 待加密的内容 byte[]publicKey - 加密所需的公钥对象 PublicKeyNoSuchPaddingExceptionNoSuchAlgorithmExceptionInvalidKeyExceptionBadPaddingExceptionIllegalBlockSizeExceptionpublic static byte[] privateDecrypt(byte[] content,
PrivateKey privateKey)
throws NoSuchPaddingException,
NoSuchAlgorithmException,
InvalidKeyException,
BadPaddingException,
IllegalBlockSizeException
content - 待解密的内容 byte[]privateKey - 解密需要的私钥对象 PrivateKeyNoSuchPaddingExceptionNoSuchAlgorithmExceptionInvalidKeyExceptionBadPaddingExceptionIllegalBlockSizeExceptionCopyright © 2021. All rights reserved.