类 WeiXinCrypto
- java.lang.Object
-
- com.ajaxjs.util.cryptography.WeiXinCrypto
-
public class WeiXinCrypto extends Object
证书和回调报文解密
-
-
构造器概要
构造器 构造器 说明 WeiXinCrypto()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static String
aesDecryptPhone(String iv, String cipherText, String sessionKey)
解密小程序提供的加密数据,返回包含手机号码等信息的 JSON 对象static String
aesDecryptToString(byte[] aesKey, byte[] associatedData, byte[] nonce, String cipherText)
AEAD_AES_256_GCM 解密static String
decryptOAEP(String cipherText, PrivateKey privateKey)
解密static String
encryptOAEP(String message, X509Certificate certificate)
加密static String
rsaEncrypt(String message, String certPath)
使用 RSA 加密算法对消息进行加密static String
rsaSign(PrivateKey privateKey, byte[] data)
对签名数据进行签名。
-
-
-
方法详细资料
-
aesDecryptToString
public static String aesDecryptToString(byte[] aesKey, byte[] associatedData, byte[] nonce, String cipherText)
AEAD_AES_256_GCM 解密- 参数:
aesKey
- key 密钥,ApiV3Key,长度必须为32个字节associatedData
- 相关数据nonce
- 随机字符串cipherText
- 密文- 返回:
- 解密后的文本
-
aesDecryptPhone
public static String aesDecryptPhone(String iv, String cipherText, String sessionKey)
解密小程序提供的加密数据,返回包含手机号码等信息的 JSON 对象- 参数:
iv
- 前端给的cipherText
- 前端给的,密文sessionKey
- 后端申请返回- 返回:
- 解密后的文本
-
encryptOAEP
public static String encryptOAEP(String message, X509Certificate certificate)
加密- 参数:
message
- 数据certificate
- 证书- 返回:
- 加密后的文本
-
decryptOAEP
public static String decryptOAEP(String cipherText, PrivateKey privateKey)
解密- 参数:
cipherText
- 密文privateKey
- 商户私钥- 返回:
- 解密后的文本
-
rsaEncrypt
public static String rsaEncrypt(String message, String certPath)
使用 RSA 加密算法对消息进行加密- 参数:
message
- 待加密的消息certPath
- 证书的路径,用于获取加密密钥- 返回:
- 加密后的消息
- 抛出:
UncheckedIOException
- 如果证书读取过程中发生 IO 错误,则抛出运行时异常
-
rsaSign
public static String rsaSign(PrivateKey privateKey, byte[] data)
对签名数据进行签名。使用商户私钥对待签名串进行 SHA256 with RSA 签名,并对签名结果进行 Base64 编码得到签名值。
- 参数:
privateKey
- 商户私钥data
- 数据- 返回:
- 签名结果
-
-