Package cn.sinozg.applet.common.utils
Class CypherUtil
java.lang.Object
cn.sinozg.applet.common.utils.CypherUtil
加密工具类,获取随机数。
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]解密数据static byte[]decryptJson(String content, String rsaPrivateKey, String aesKey) 解密前端传过来的加密数据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加密信息static Object加密数据返回到前端private static AesRsaEncrypt随机生成16位的 aes私钥static String加密数据private static String获取随机的 aes密钥 必须是 8的倍数static KeyPair生成秘钥对static booleanmatches(CharSequence rawPassword, String encodedPassword) 密码匹配static Stringmd5 加密static Stringmd5 加密返回大写static Key通过字符串等到 key对象static boolean签名判断 参数排序拼接后 签名再与原始的签名比较static StringsignMessage(boolean sha2, String... params) 签名static String解密微信用户信息
-
Field Details
-
AES_ALGORITHM
- See Also:
-
RSA_ALGORITHM
- See Also:
-
PKCS7
- See Also:
-
ENCODER
private static final org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder ENCODER -
log
private static final org.slf4j.Logger log
-
-
Constructor Details
-
CypherUtil
private CypherUtil()
-
-
Method Details
-
signature
签名判断 参数排序拼接后 签名再与原始的签名比较- Parameters:
sha2- 是否为 sha2signature- 签名字符串params- 要签名的数据- Returns:
- 是否与签名一致
-
signMessage
签名- Parameters:
sha2- sha2 是否为 sha2params- 要签名的数据- Returns:
- 签名值
-
wxDecrypt
解密微信用户信息- Parameters:
encryptedData- 加密数据sessionKey- 解密秘钥iv- 初始向量- Returns:
- 解密以后的数据
-
encoder
加密信息- Parameters:
rawPassword- 原始密码- Returns:
- 加密后的密码
-
matches
密码匹配- Parameters:
rawPassword- 原始密码encodedPassword- 加密后的密码- Returns:
- 是否匹配
-
md5Upper
md5 加密返回大写- Parameters:
input- 要加密的数据- Returns:
- md5
-
md5
md5 加密- Parameters:
input- 要加密的数据- Returns:
- md5
-
decryptJson
public static byte[] decryptJson(String content, String rsaPrivateKey, String aesKey) throws Exception 解密前端传过来的加密数据先用RSA私钥(java)解密前端传过来的aes加密信息,得到前端生成的随机aes key
再用 aes key解密得到数据
- Parameters:
content- 加密数据rsaPrivateKey- RSA私钥aesKey- aes 加密后的数据- Returns:
- 解密后的数据
- Throws:
Exception
-
encrypt
public static Object encrypt(jakarta.servlet.http.HttpServletRequest request, Object data) throws IOException 加密数据返回到前端- Parameters:
request- requestdata- 请求参数- Returns:
- 请求参数或者加密后的数据
- Throws:
IOException
-
encrypt
随机生成16位的 aes私钥用aes 私钥加密json得到加密信息
用前端传过来的 RSA 公钥加密 aes私钥 得到aes私钥加密信息
- Parameters:
content- 加密信息rsaPublicKey- 前端传过来的RSA公钥- Returns:
- 加密信息
- Throws:
Exception
-
rsaKey
通过字符串等到 key对象- Parameters:
key- key的字符串isPublic- 是否为公钥- Returns:
- 对象
- Throws:
Exception- 异常
-
decrypt
解密数据- Parameters:
transformation- 加密方式key- 密钥input- 数据- Returns:
- 返回操作后的结果
-
encrypt
加密数据- Parameters:
transformation- 加密方式key- 密钥input- 数据- Returns:
- 返回操作后的结果
-
doFinalRsa
rsa 加密或者解密数据 分段- Parameters:
transformation- 加密方式opMode- 加密、解密key- 密钥input- 数据- Returns:
- 返回操作后的结果
-
doFinalAes
aes 签名- Parameters:
transformation- 签名方法decrypt- 加密或者解密input- 文本信息aesKey- 密钥- Returns:
- 加解密后的字节信息
-
doFinalAes
public static byte[] doFinalAes(String transformation, boolean decrypt, byte[] input, byte[] aesKey, byte[] ivKey) aes 签名- Parameters:
transformation- 签名方法decrypt- 加密或者解密input- 文本信息aesKey- 密钥ivKey- 密钥偏移量- Returns:
- 加解密后的字节信息
-
doFinalAes
private static byte[] doFinalAes(String transformation, boolean decrypt, byte[] input, byte[] aesKey, byte[] ivKey, Key aesPriKey) aes 签名- Parameters:
transformation- 签名方法decrypt- 加密或者解密input- 文本信息aesKey- 密钥ivKey- 偏移量aesPriKey- 密钥- Returns:
- 加解密后的字节信息
-
getAesKey
获取随机的 aes密钥 必须是 8的倍数- Returns:
- 密钥
- Throws:
Exception
-
getKeyPair
生成秘钥对- Returns:
- rsa密钥对
- Throws:
Exception- 异常
-