删除NettyBase64类

This commit is contained in:
jinyu 2017-03-09 10:37:38 +08:00
parent 3e022ad101
commit 08d6a84d7f
2 changed files with 5 additions and 49 deletions

View File

@ -6,6 +6,7 @@ import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import com.foxinmy.weixin4j.base64.Base64;
import com.foxinmy.weixin4j.exception.WeixinException; import com.foxinmy.weixin4j.exception.WeixinException;
/** /**
@ -89,7 +90,7 @@ public final class MessageUtil {
byteLength += appidBytes.length; byteLength += appidBytes.length;
System.arraycopy(padBytes, 0, unencrypted, byteLength, padBytes.length); System.arraycopy(padBytes, 0, unencrypted, byteLength, padBytes.length);
try { try {
byte[] aesKey = NettyBase64.decodeBase64(encodingAesKey + "="); byte[] aesKey = Base64.decodeBase64(encodingAesKey + "=");
// 设置加密模式为AES的CBC模式 // 设置加密模式为AES的CBC模式
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
SecretKeySpec keySpec = new SecretKeySpec(aesKey, ServerToolkits.AES); SecretKeySpec keySpec = new SecretKeySpec(aesKey, ServerToolkits.AES);
@ -99,7 +100,7 @@ public final class MessageUtil {
byte[] encrypted = cipher.doFinal(unencrypted); byte[] encrypted = cipher.doFinal(unencrypted);
// 使用BASE64对加密后的字符串进行编码 // 使用BASE64对加密后的字符串进行编码
// return Base64.encodeBase64String(encrypted); // return Base64.encodeBase64String(encrypted);
return com.foxinmy.weixin4j.base64.Base64 return Base64
.encodeBase64String(encrypted); .encodeBase64String(encrypted);
} catch (Exception e) { } catch (Exception e) {
throw new WeixinException("-40006", "AES加密失败:" + e.getMessage()); throw new WeixinException("-40006", "AES加密失败:" + e.getMessage());
@ -119,7 +120,7 @@ public final class MessageUtil {
*/ */
public static String aesDecrypt(String appId, String encodingAesKey, public static String aesDecrypt(String appId, String encodingAesKey,
String encryptContent) throws WeixinException { String encryptContent) throws WeixinException {
byte[] aesKey = NettyBase64.decodeBase64(encodingAesKey + "="); byte[] aesKey = Base64.decodeBase64(encodingAesKey + "=");
byte[] original; byte[] original;
try { try {
// 设置解密模式为AES的CBC模式 // 设置解密模式为AES的CBC模式
@ -129,7 +130,7 @@ public final class MessageUtil {
0, 16)); 0, 16));
cipher.init(Cipher.DECRYPT_MODE, key_spec, iv); cipher.init(Cipher.DECRYPT_MODE, key_spec, iv);
// 使用BASE64对密文进行解码 // 使用BASE64对密文进行解码
byte[] encrypted = NettyBase64.decodeBase64(encryptContent); byte[] encrypted = Base64.decodeBase64(encryptContent);
// 解密 // 解密
original = cipher.doFinal(encrypted); original = cipher.doFinal(encrypted);
} catch (Exception e) { } catch (Exception e) {

View File

@ -1,45 +0,0 @@
package com.foxinmy.weixin4j.util;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.base64.Base64Dialect;
/**
* NettyBase64
*
* @className NettyBase64
* @author jinyu(foxinmy@gmail.com)
* @date 2015年5月17日
* @since JDK 1.6
* @see
*/
public final class NettyBase64 {
private static byte[] byteBuf2Array(ByteBuf byteBuf) {
if (byteBuf.hasArray()) {
return byteBuf.array();
} else {
byte[] desArray = new byte[byteBuf.readableBytes()];
byteBuf.readBytes(desArray);
return desArray;
}
}
public static byte[] decodeBase64(final String content) {
byte[] data = ServerToolkits.getBytesUtf8(content);
ByteBuf des = io.netty.handler.codec.base64.Base64.decode(
Unpooled.copiedBuffer(data), Base64Dialect.STANDARD);
return byteBuf2Array(des);
}
public static byte[] encodeBase64(final byte[] bytes) {
ByteBuf des = io.netty.handler.codec.base64.Base64.encode(
Unpooled.copiedBuffer(bytes), Base64Dialect.STANDARD);
return byteBuf2Array(des);
}
public static String encodeBase64String(final byte[] bytes) {
byte[] data = encodeBase64(bytes);
return ServerToolkits.newStringUtf8(data);
}
}