类 WeiXinCrypto


  • public class WeiXinCrypto
    extends Object
    证书和回调报文解密
    • 构造器详细资料

      • WeiXinCrypto

        public WeiXinCrypto()
    • 方法详细资料

      • 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 - 数据
        返回:
        签名结果