public class CypherUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
AES_ALGORITHM |
private static org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder |
ENCODER |
private static org.slf4j.Logger |
log |
private static String |
PKCS7 |
static String |
RSA_ALGORITHM |
| Modifier | Constructor and Description |
|---|---|
private |
CypherUtil() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
decrypt(String transformation,
Key key,
String input)
解密数据
|
static byte[] |
decryptJson(String content,
String rsaPrivateKey,
String aesKey)
解密前端传过来的加密数据
先用RSA私钥(java)解密前端传过来的aes加密信息,得到前端生成的随机aes key
再用 aes key解密得到数据
|
static byte[] |
doFinalAes(String transformation,
boolean decrypt,
byte[] input,
byte[] aesKey,
byte[] ivKey)
aes 签名
|
private static byte[] |
doFinalAes(String transformation,
boolean decrypt,
byte[] input,
byte[] aesKey,
byte[] ivKey,
Key aesPriKey)
aes 签名
|
static byte[] |
doFinalAes(String transformation,
boolean decrypt,
byte[] input,
Key aesKey)
aes 签名
|
private static byte[] |
doFinalRsa(String transformation,
int opMode,
Key key,
byte[] input)
rsa 加密或者解密数据 分段
|
static String |
encoder(String rawPassword)
加密信息
|
static Object |
encrypt(javax.servlet.http.HttpServletRequest request,
Object data)
加密数据返回到前端
|
static String |
encrypt(String transformation,
Key key,
String input)
加密数据
|
private static AesRsaEncrypt |
encrypt(String content,
String rsaPublicKey)
随机生成16位的 aes私钥
用aes 私钥加密json得到加密信息
用前端传过来的 RSA 公钥加密 aes私钥 得到aes私钥加密信息
|
private static String |
getAesKey()
获取随机的 aes密钥 必须是 8的倍数
|
static KeyPair |
getKeyPair()
生成秘钥对
|
static boolean |
matches(CharSequence rawPassword,
String encodedPassword)
密码匹配
|
static String |
md5(String input)
md5 加密
|
static String |
md5Upper(String input)
md5 加密返回大写
|
static Key |
rsaKey(String key,
boolean isPublic)
通过字符串等到 key对象
|
static boolean |
signature(boolean sha2,
String signature,
String... params)
签名判断 参数排序拼接后 签名再与原始的签名比较
|
static String |
signMessage(boolean sha2,
String... params)
签名
|
static String |
wxDecrypt(String encryptedData,
String sessionKey,
String iv)
解密微信用户信息
|
public static final String AES_ALGORITHM
public static final String RSA_ALGORITHM
private static final String PKCS7
private static final org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder ENCODER
private static final org.slf4j.Logger log
public static boolean signature(boolean sha2,
String signature,
String... params)
sha2 - 是否为 sha2signature - 签名字符串params - 要签名的数据public static String signMessage(boolean sha2, String... params)
sha2 - sha2 是否为 sha2params - 要签名的数据public static String wxDecrypt(String encryptedData, String sessionKey, String iv)
encryptedData - 加密数据sessionKey - 解密秘钥iv - 初始向量public static String encoder(String rawPassword)
rawPassword - 原始密码public static boolean matches(CharSequence rawPassword, String encodedPassword)
rawPassword - 原始密码encodedPassword - 加密后的密码public static String md5Upper(String input)
input - 要加密的数据public static byte[] decryptJson(String content, String rsaPrivateKey, String aesKey) throws Exception
先用RSA私钥(java)解密前端传过来的aes加密信息,得到前端生成的随机aes key
再用 aes key解密得到数据
content - 加密数据rsaPrivateKey - RSA私钥aesKey - aes 加密后的数据Exceptionpublic static Object encrypt(javax.servlet.http.HttpServletRequest request, Object data) throws IOException
request - requestdata - 请求参数IOExceptionprivate static AesRsaEncrypt encrypt(String content, String rsaPublicKey) throws Exception
用aes 私钥加密json得到加密信息
用前端传过来的 RSA 公钥加密 aes私钥 得到aes私钥加密信息
content - 加密信息rsaPublicKey - 前端传过来的RSA公钥Exceptionpublic static Key rsaKey(String key, boolean isPublic) throws Exception
key - key的字符串isPublic - 是否为公钥Exception - 异常public static byte[] decrypt(String transformation, Key key, String input)
transformation - 加密方式key - 密钥input - 数据public static String encrypt(String transformation, Key key, String input)
transformation - 加密方式key - 密钥input - 数据private static byte[] doFinalRsa(String transformation, int opMode, Key key, byte[] input)
transformation - 加密方式opMode - 加密、解密key - 密钥input - 数据public static byte[] doFinalAes(String transformation, boolean decrypt, byte[] input, Key aesKey)
transformation - 签名方法decrypt - 加密或者解密input - 文本信息aesKey - 密钥public static byte[] doFinalAes(String transformation, boolean decrypt, byte[] input, byte[] aesKey, byte[] ivKey)
transformation - 签名方法decrypt - 加密或者解密input - 文本信息aesKey - 密钥ivKey - 密钥偏移量private static byte[] doFinalAes(String transformation, boolean decrypt, byte[] input, byte[] aesKey, byte[] ivKey, Key aesPriKey)
transformation - 签名方法decrypt - 加密或者解密input - 文本信息aesKey - 密钥ivKey - 偏移量aesPriKey - 密钥private static String getAesKey() throws Exception
ExceptionCopyright © 2024. All rights reserved.