安全模式下的加解密

来源:互联网 发布:网络宣传阵地建设ppt 编辑:程序博客网 时间:2024/05/21 08:00

首先通过request获取微信服务器发来的加解密类型:encrypt_type

// 加解密类型String encrypt_type = request.getParameter("encrypt_type");
当encrypt_type的值为“aes”时,说明微信开发下使用的是安全模式,若为null则为明文模式,若为raw则为兼容模式。

加密(其中replyMsg为明文的xml,WXBizMsgCrypt是微信开发文档里面下的官方包中的一个类):

WXBizMsgCrypt pc = new WXBizMsgCrypt(token, encodingAesKey, appId);String miwen = pc.encryptMsg(replyMsg, timestamp, nonce);System.out.println("加密后: " + miwen);

解密(fromXML为密文的xml):

String mingwen = pc.decryptMsg(msgSignature, timestamp, nonce, fromXML);


0 0