ECC私钥比公钥长

时间:2016-05-27 07:39:24

标签: bouncycastle private-key public-key elliptic-curve java-security

我使用secp192r1曲线生成了ECC公钥和私钥。我得到75为公共和125为私人编码键长度。为什么私钥比公钥长?为什么私钥不比公众长两倍?为什么私钥不是192位= 24字节,因为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);

1 个答案:

答案 0 :(得分:0)

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

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);