本文介绍了ECC私钥长于公钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用secp192r1曲线生成了ECC公钥和私钥。对于公共,我得到75,对于私有编码的密钥数组长度,我得到125。为什么私钥比公钥长?为什么私钥不超过公钥的两倍?为什么由于secp192r1,私钥不是192位= 24字节?

I have generated ECC public and private key using secp192r1 curve. I get 75 for public and 125 for private encoded key array length. Why private key is longer than public key? Why private key is not longer two times than public? Why private key is not 192 bits = 24 bytes because of secp192r1?

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

ECNamedCurveParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("secp192r1");

KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC");
g.initialize(ecSpec, new SecureRandom());
KeyPair pair = g.generateKeyPair();

System.out.println(pair.getPublic().getEncoded().length);
System.out.println(pair.getPrivate().getEncoded().length);


推荐答案

下面的代码片段输出24个字节的私钥:

Code fragment below outputs 24 bytes private key:

Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());

ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec("secp192r1");

KeyPairGenerator g = KeyPairGenerator.getInstance("ECDSA", "BC");
g.initialize(spec, new SecureRandom());
KeyPair pair = g.generateKeyPair();
ECPrivateKey ecPrivateKey = (ECPrivateKey)pair.getPrivate();

System.out.println(ecPrivateKey.getS().toByteArray().length);

这篇关于ECC私钥长于公钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-11 17:25