ECC private key is longer than public key

僤鯓⒐⒋嵵緔 提交于 2019-12-02 16:00:41

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/37477586/ecc-private-key-is-longer-than-public-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!