Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SM2的公私钥生成后,怎么根据公钥值(pubKey.getQ().getEncoded(false))得到ECPublicKeyParameters对象 #2

Closed
shijl80 opened this issue Aug 9, 2018 · 7 comments

Comments

@shijl80
Copy link

shijl80 commented Aug 9, 2018

请问下,SM2的公私钥生成后,先保存公钥值(pubKey.getQ().getEncoded(false)),
之后怎么根据这个值重新生成ECPublicKeyParameters对象?
还有私钥参数对象(ECPrivateKeyParameters)?

@ZZMarquis
Copy link
Owner

ZZMarquis commented Aug 11, 2018

BCECUtil里增加了createEcPublicKey方法,结合Sm2UtilTest里的测试代码,参考一下

@shijl80
Copy link
Author

shijl80 commented Aug 13, 2018

BCECUtil没看到啊,是还没提交么?

@ZZMarquis
Copy link
Owner

提交了,你pull一下

@shijl80
Copy link
Author

shijl80 commented Aug 13, 2018

看到了,不过还是没搞懂那个x、y是啥。
我是想先生成一对公私钥,然后把公钥HexString发给别人,用私钥来解密,暂时是用convertEcPubKeyToX509Der转了后,再写个方法把X509Der转回来成ECPublicKeyParameters。
另外,SM2Util.encryt方法名称拼写错误......

@ZZMarquis
Copy link
Owner

@shijl80 感谢指正错误
xy是ecc公钥的两个分量,是两个大数,在知道曲线和xy分量的情况下就可以确定一个ecc公钥

@shijl80
Copy link
Author

shijl80 commented Aug 14, 2018

非常感谢!已经成功通过
new ECPublicKeyParameters(curve.decodePoint(ByteUtils.fromHexString(encodedPubHex)), domainParameters)
生成公钥,
通过new ECPrivateKeyParameters(new BigInteger(ByteUtils.fromHexString(priHex)), domainParameters)
生成私钥。
网上国密相关资料太少,要是有个系列的教程就好了。
已经验证SM4可以与guan zhi的那个Gmssl互相加解密。

@ZZMarquis
Copy link
Owner

@shijl80
嗯。我也用过guan zhi的GmSSL。原生OpenSLL-1.1.1也开始支持国密算法了,有空可以研究交流一下。
那这个issue就先关了。有别的问题可以再开issue。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants