本教程提供了 WeiXinCrypto 类的概述,该类是 lightweight-component/aj-util 库的一部分。WeiXinCrypto 类为微信相关操作提供了加密和解密实用工具。
WeiXinCrypto 类包含用于处理微信加密和解密操作的静态方法,包括:
aesDecryptToString(byte[] aesKey, byte[] associatedData, byte[] nonce, String cipherText) - AEAD_AES_256_GCM 解密aesDecryptPhone(String iv, String cipherText, String sessionKey) - 小程序手机号解密encryptOAEP(String message, X509Certificate certificate) - RSA-OAEP 加密decryptOAEP(String cipherText, PrivateKey privateKey) - RSA-OAEP 解密rsaEncrypt(String message, String certPath) - 使用证书文件的 RSA 加密rsaSign(PrivateKey privateKey, byte[] data) - RSA 签名生成String decrypted = WeiXinCrypto.aesDecryptToString(
apiKey.getBytes(),
associatedData.getBytes(),
nonce.getBytes(),
cipherText
);
String phone = WeiXinCrypto.aesDecryptPhone(iv, cipherText, sessionKey);
String encrypted = WeiXinCrypto.encryptOAEP(message, certificate);
String encryptedFromFile = WeiXinCrypto.rsaEncrypt(message, "path/to/cert.pem");
String decrypted = WeiXinCrypto.decryptOAEP(cipherText, privateKey);
String signature = WeiXinCrypto.rsaSign(privateKey, data.getBytes());
WeiXinCrypto 类提供了全面的实用工具,用于处理微信相关的加密操作,使与微信服务的集成更加方便。