From 1a9d4ff1f946b3427c9c0ee4eb577a4c120ae1a6 Mon Sep 17 00:00:00 2001 From: jinyu Date: Sun, 9 Aug 2015 11:47:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4PKCS7Encoder=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../foxinmy/weixin4j/util/PKCS7Encoder.java | 72 ------------------- 1 file changed, 72 deletions(-) delete mode 100644 weixin4j-base/src/main/java/com/foxinmy/weixin4j/util/PKCS7Encoder.java diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/util/PKCS7Encoder.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/util/PKCS7Encoder.java deleted file mode 100644 index 5f2beb20..00000000 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/util/PKCS7Encoder.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * 对公众平台发送给公众账号的消息加解密示例代码. - * - * @copyright Copyright (c) 1998-2014 Tencent Inc. - */ - -// ------------------------------------------------------------------------ - -package com.foxinmy.weixin4j.util; - -import java.util.Arrays; - -import com.foxinmy.weixin4j.model.Consts; - -/** - * 提供基于PKCS7算法的加解密接口
- * 提供接收和推送给公众平台消息的加解密接口(UTF8编码的字符串). - *
    - *
  1. 第三方回复加密消息给公众平台
  2. - *
  3. 第三方收到公众平台发送的消息,验证消息的安全性,并对消息进行解密。
  4. - *
- * 说明:异常java.security.InvalidKeyException:illegal Key Size的解决方案 - *
    - *
  1. 在官方网站下载JCE无限制权限策略文件(JDK7的下载地址: - * http://www.oracle.com/technetwork/java/javase - * /downloads/jce-7-download-432124.html
  2. - *
  3. 下载后解压,可以看到local_policy.jar和US_export_policy.jar以及readme.txt
  4. - *
  5. 如果安装了JRE,将两个jar文件放到%JRE_HOME%\lib\security目录下覆盖原来的文件
  6. - *
  7. 如果安装了JDK,将两个jar文件放到%JDK_HOME%\jre\lib\security目录下覆盖原来文件
  8. - *
- */ -public class PKCS7Encoder { - private final static int BLOCK_SIZE = 32; - - /** - * 获得对明文进行补位填充的字节. - * - * @param count - * 需要进行填充补位操作的明文字节个数 - * @return 补齐用的字节数组 - */ - public static byte[] encode(int count) { - // 计算需要填充的位数 - int amountToPad = BLOCK_SIZE - (count % BLOCK_SIZE); - if (amountToPad == 0) { - amountToPad = BLOCK_SIZE; - } - // 获得补位所用的字符 - byte target = (byte) (amountToPad & 0xFF); - char padChr = (char) target; - StringBuilder tmp = new StringBuilder(); - for (int index = 0; index < amountToPad; index++) { - tmp.append(padChr); - } - return tmp.toString().getBytes(Consts.UTF_8); - } - - /** - * 删除解密后明文的补位字符 - * - * @param decrypted - * 解密后的明文 - * @return 删除补位字符后的明文 - */ - public static byte[] decode(byte[] decrypted) { - int pad = (int) decrypted[decrypted.length - 1]; - if (pad < 1 || pad > 32) { - pad = 0; - } - return Arrays.copyOfRange(decrypted, 0, decrypted.length - pad); - } -} \ No newline at end of file