收藏
回答

微信推送的密文解密失败?

AppID
wx8034f64efdb06ed8

jdk版本:1.8

commons-codec版本:1.9

遇到两个问题:

第一个问题:

如果依赖的commons-codec版本为1.14,构建WXBizMsgCrypt时直接报错:

这一行:
aesKey = Base64.decodeBase64(encodingAesKey + "=");

Exception in thread "main" java.lang.IllegalArgumentException: Last encoded character (before the paddings if any) is a valid base 64 alphabet but not a possible value. Expected the discarded bits to be zero.
	at org.apache.commons.codec.binary.Base64.validateCharacter(Base64.java:803)
	at org.apache.commons.codec.binary.Base64.decode(Base64.java:482)
	at org.apache.commons.codec.binary.BaseNCodec.decode(BaseNCodec.java:481)
	at org.apache.commons.codec.binary.BaseNCodec.decode(BaseNCodec.java:465

改成1.9就不报错了

第二个问题:改成1.9之后,验签没问题了,但是解密微信推送的密文时又报错了:

这一行:
cipher.init(Cipher.DECRYPT_MODE, key_spec, iv);

java.security.InvalidKeyException: Illegal key size
	at javax.crypto.Cipher.checkCryptoPerm(Cipher.java:1039)
	at javax.crypto.Cipher.implInit(Cipher.java:805)
	at javax.crypto.Cipher.chooseProvider(Cipher.java:864)
	at javax.crypto.Cipher.init(Cipher.java:1396)
	at javax.crypto.Cipher.init(Cipher.java:1327)


回答关注问题邀请回答
收藏

1 个回答

  • liuyfly
    liuyfly
    05-24

    感觉还是这个base64编码解码的问题

    05-24
    有用
    回复
登录 后发表内容
问题标签