public class AESMsgCrypt extends Object
AES 消息加解密
说明:异常java.security.InvalidKeyException:illegal Key Size的解决方案| 构造器和说明 |
|---|
AESMsgCrypt(String token,
String encodingAesKey,
String appId)
构造函数
|
| 限定符和类型 | 方法和说明 |
|---|---|
String |
decrypt(String text)
对密文进行解密
|
String |
decryptMsg(String msgSignature,
String timeStamp,
String nonce,
String encrypt)
检验消息的真实性,并且获取解密后的明文.
|
String |
encrypt(String text)
对明文进行加密 16 位随机数加密混淆
|
String |
encryptJSONMsg(String replyMsg,
String timeStamp,
String nonce) |
protected String |
encryptMsg(String replyMsg,
String timeStamp,
String nonce,
boolean isXMLParser)
将公众平台回复用户的消息加密打包.
|
String |
encryptXMLMsg(String replyMsg,
String timeStamp,
String nonce) |
byte[] |
getNetworkBytesOrder(int sourceNumber)
生成4个字节的网络字节序
|
int |
recoverNetworkBytesOrder(byte[] orderBytes)
还原4个字节的网络字节序
|
String |
verifyUrl(String msgSignature,
String timeStamp,
String nonce,
String echoStr)
验证 URL
|
public AESMsgCrypt(String token, String encodingAesKey, String appId) throws AESException
构造函数
token - API 平台上,开发者设置的tokenencodingAesKey - API 平台上,开发者设置的EncodingAESKeyappId - API 平台 appidAESException - AESExceptionpublic byte[] getNetworkBytesOrder(int sourceNumber)
生成4个字节的网络字节序
sourceNumber - public int recoverNetworkBytesOrder(byte[] orderBytes)
还原4个字节的网络字节序
orderBytes - public String encrypt(String text) throws AESException
对明文进行加密 16 位随机数加密混淆
text - 需要加密的明文AESException - AESExceptionpublic String decrypt(String text) throws AESException
对密文进行解密
text - 需要解密的密文AESException - AESExceptionpublic String encryptXMLMsg(String replyMsg, String timeStamp, String nonce) throws AESException
AESExceptionpublic String encryptJSONMsg(String replyMsg, String timeStamp, String nonce) throws AESException
AESExceptionprotected String encryptMsg(String replyMsg, String timeStamp, String nonce, boolean isXMLParser) throws AESException
将公众平台回复用户的消息加密打包.
replyMsg - 公众平台待回复用户的消息,xml格式的字符串timeStamp - 时间戳,可以自己生成,也可以用URL参数的timestampnonce - 随机串,可以自己生成,也可以用URL参数的nonceisXMLParser - true XML 解析 ,false JSON 解析AESException - AESExceptionpublic String decryptMsg(String msgSignature, String timeStamp, String nonce, String encrypt) throws AESException
检验消息的真实性,并且获取解密后的明文.
msgSignature - 签名串,对应URL参数的msg_signaturetimeStamp - 时间戳,对应URL参数的timestampnonce - 随机串,对应URL参数的nonceencrypt - 密文,对应POST请求的数据AESException - AESExceptionpublic String verifyUrl(String msgSignature, String timeStamp, String nonce, String echoStr) throws AESException
验证 URL
msgSignature - 签名串,对应URL参数的msg_signaturetimeStamp - 时间戳,对应URL参数的timestampnonce - 随机串,对应URL参数的nonceechoStr - 随机串,对应URL参数的echostrAESException - AESExceptionCopyright © 2016. All rights reserved.