Java 与 Python 国密算法 SM2 交互使用(qbit)
文章目录
前言
- Java 库 https://github.com/dromara/hu...
- Python 库 https://github.com/duanhongyi...
- 背景:Java
hutool库生成的密钥,Pythongmssl签名校验不通过,折腾了很久才找到原因
原因
开始
hutool这样生成的密钥,gmssl死活通不过签名校验SM2 sm2 = new SM2(); sm2.setMode(SM2Engine.Mode.C1C2C3); sm2.setDigest(new SM3Digest()); privateKey = HexUtil.encodeHexStr(sm2.getPrivateKey().getEncoded()) publicKey = HexUtil.encodeHexStr(sm2.getPublicKey().getEncoded())hutool正确生成密钥的方式privateKey = HexUtil.encodeHexStr(sm2.getD()) publicKey = HexUtil.encodeHexStr(sm2.getQ(false)) // 公钥不压缩 // 等价于 privateKey = HexUtil.encodeHexStr(BCUtil.encodeECPrivateKey(sm2.getPrivateKey())) publicKey = HexUtil.encodeHexStr(((BCECPublicKey) sm2.getPublicKey()).getQ().getEncoded(false))
本文出自 qbit snap

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论