1
0
mirror of synced 2025-12-16 20:28:11 +08:00

🎨 避免对曾变化的guava方法的依赖,以免对使用不同版本guava的用户造成困惑

This commit is contained in:
Binary Wang
2022-07-24 21:59:47 +08:00
parent 7cd213da65
commit 0cfcc8d4a0
8 changed files with 28 additions and 19 deletions

View File

@@ -1,10 +1,10 @@
package me.chanjar.weixin.cp.util.crypto;
import com.google.common.base.CharMatcher;
import com.google.common.io.BaseEncoding;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import org.apache.commons.lang3.StringUtils;
import sun.security.util.DerInputStream;
import sun.security.util.DerValue;
@@ -28,7 +28,7 @@ public class WxCpCryptUtil extends WxCryptUtil {
this.token = token;
this.appidOrCorpid = corpId;
this.aesKey = BaseEncoding.base64().decode(CharMatcher.whitespace().removeFrom(encodingAesKey));
this.aesKey = Base64.getDecoder().decode(StringUtils.remove(encodingAesKey, " "));
}
/**

View File

@@ -4,6 +4,9 @@ import com.google.common.base.CharMatcher;
import com.google.common.io.BaseEncoding;
import me.chanjar.weixin.common.util.crypto.WxCryptUtil;
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
import org.apache.commons.lang3.StringUtils;
import java.util.Base64;
/**
* @author someone
@@ -24,7 +27,7 @@ public class WxCpTpCryptUtil extends WxCryptUtil {
this.token = token;
this.appidOrCorpid = corpId;
this.aesKey = BaseEncoding.base64().decode(CharMatcher.whitespace().removeFrom(encodingAesKey));
this.aesKey = Base64.getDecoder().decode(StringUtils.remove(encodingAesKey, " "));
}

View File

@@ -1,8 +1,7 @@
package me.chanjar.weixin.cp.util.crypto;
import com.google.common.base.CharMatcher;
import com.google.common.io.BaseEncoding;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.testng.annotations.Test;
import static org.testng.Assert.assertEquals;
@@ -16,8 +15,8 @@ public class WxCpCryptUtilTest {
public void test() {
String encodingAesKey = "jWmYm7qr5nMoAUwZRjGtBxmz3KA1tkAj3ykkR6q2B2C";
final byte[] commonsCodec = Base64.decodeBase64(encodingAesKey + "=");
final byte[] guava = BaseEncoding.base64().decode(CharMatcher.whitespace().removeFrom(encodingAesKey));
final byte[] guava1 = BaseEncoding.base64().decode(CharMatcher.whitespace().removeFrom(encodingAesKey + "="));
final byte[] guava = java.util.Base64.getDecoder().decode(StringUtils.remove(encodingAesKey, " "));
final byte[] guava1 = java.util.Base64.getDecoder().decode(StringUtils.remove(encodingAesKey + "=", " "));
assertEquals(commonsCodec, guava);
assertEquals(guava1, guava);
}