收藏
回答

小程序安全键盘输入内容后获取到的加密字符串该如何解密?

获取到的加密字符串是:

V02_3081D302204C0E940DEF67CC50B8C5639810B02FE17E86368A0CC9BAB7D79EE20EFA4BA379022100885D7E995AC8401DDC51DA242C3138DFB9888999284976E0655C2D7E71A475150420E6097CB081058BC3D5B7CD788654102D3CCE6DD517772C1627B2D131F362287E046ABD14E9E4733873A3DE9EE267C602D1A9296A28D7D53C0512D57A1F4086BBF1CE497E201894B5BBDC1A357484885C142F7606D094BCDE82A2FB13DE16FBFD3E2CDBA56B481C913CC873331F007B5B8284832563A0B98A528C35813B175E31E0131585B8F0CEBA10B8E1E3

然后后台java解密出现异常是:

java.lang.ClassCastException: org.bouncycastle.asn1.DLApplicationSpecific cannot be cast to org.bouncycastle.asn1.ASN1Sequence


BigInteger privateKeyD = new BigInteger(privateKeyStr, 16);
ECPrivateKeyParameters privateKeyParameters = new ECPrivateKeyParameters(privateKeyD, ecDomainParameters);
//解密-------------------------------------------------------------------------------------------------------

//用私钥解密
ZSM2Engine sm2EngineDec = new ZSM2Engine();
sm2EngineDec.init(false, privateKeyParameters);
byte[] arrayOfBytes = null;
try {
    arrayOfBytes = sm2EngineDec.processBlock(encryptData, 0, encryptData.length);
} catch (IOException e) {
    e.printStackTrace();
} catch (InvalidCipherTextException e) {
    e.printStackTrace();
}
//得到明文:SM2 Encryption Test
data = new String(arrayOfBytes);
return data;


求助 给一个前端加密,后台java解密的例子。谢谢


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

2 个回答

  • Demons
    Demons
    2022-02-09

    参考一下;https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/safe-password.html

    2022-02-09
    有用
    回复 2
    • 汤化峰
      汤化峰
      2022-02-10
      就是按照这个文档做的,但是解密不出来啊。先移除加密串前面的V02_,剩下的串,进行sm2解密,解密不出来,报错java.lang.ClassCastException: org.bouncycastle.asn1.DLApplicationSpecific cannot be cast to org.bouncycastle.asn1.ASN1Sequence。希望能提供一个完整的案例 谢谢
      2022-02-10
      回复
    • 舜
      09-03回复汤化峰
      实现了解密了吗
      09-03
      回复
  • 怀羽ᑋᵉᑊᑊᵒ
    怀羽ᑋᵉᑊᑊᵒ
    2022-05-11

    好歹给一个后端的例子啊,怎么加密怎么解密的例子啊

    2022-05-11
    有用 1
    回复
登录 后发表内容