com.foxinmy.weixin4j.util
Class PKCS7Encoder

java.lang.Object
  extended by com.foxinmy.weixin4j.util.PKCS7Encoder

public class PKCS7Encoder
extends Object

提供基于PKCS7算法的加解密接口
提供接收和推送给公众平台消息的加解密接口(UTF8编码的字符串).

  1. 第三方回复加密消息给公众平台
  2. 第三方收到公众平台发送的消息,验证消息的安全性,并对消息进行解密。
说明:异常java.security.InvalidKeyException:illegal Key Size的解决方案
  1. 在官方网站下载JCE无限制权限策略文件(JDK7的下载地址: http://www.oracle.com/technetwork/java/javase /downloads/jce-7-download-432124.html
  2. 下载后解压,可以看到local_policy.jar和US_export_policy.jar以及readme.txt
  3. 如果安装了JRE,将两个jar文件放到%JRE_HOME%\lib\security目录下覆盖原来的文件
  4. 如果安装了JDK,将两个jar文件放到%JDK_HOME%\jre\lib\security目录下覆盖原来文件


Constructor Summary
PKCS7Encoder()
           
 
Method Summary
static byte[] decode(byte[] decrypted)
          删除解密后明文的补位字符
static byte[] encode(int count)
          获得对明文进行补位填充的字节.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PKCS7Encoder

public PKCS7Encoder()
Method Detail

encode

public static byte[] encode(int count)
获得对明文进行补位填充的字节.

Parameters:
count - 需要进行填充补位操作的明文字节个数
Returns:
补齐用的字节数组

decode

public static byte[] decode(byte[] decrypted)
删除解密后明文的补位字符

Parameters:
decrypted - 解密后的明文
Returns:
删除补位字符后的明文


Copyright © 2014–2017. All rights reserved.