我使用ECC生成密钥。我需要添加随机数和密钥,即x=r+s
。这是我的代码:
KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECDSA", "BC");
kpg.initialize(ecSpec, new SecureRandom());
KeyPair keyPair = kpg.generateKeyPair();
PublicKey pubKey = keyPair.getPublic();
System.out.println(pubKey);
PrivateKey privKey = keyPair.getPrivate();
System.out.println(privKey);
Random rand = new Random();
int numNoRange = rand.nextInt();
现在我需要添加x=numNoRange+privkey
;但我无法添加它。对新想法的任何建议?
答案 0 :(得分:0)
您可以通过将私钥转换为BigInteger
来提取ECPrivateKey
,如下例所示:
BigInteger s = ((ECPrivateKey) privKey).getS();