[英]when I am executing the code only public key is generated but not the private key ,so what should I do?
package com.project;
import java.security.*;
import java.security.spec.*;
public class ECCKeyGeneration {
public static void main(String[] args) throws Exception {
KeyPairGenerator kpg;
kpg = KeyPairGenerator.getInstance("EC","SunEC");
ECGenParameterSpec ecsp;
ecsp = new ECGenParameterSpec("secp192r1");
kpg.initialize(ecsp);
KeyPair kp = kpg.genKeyPair();
PrivateKey privKey = kp.getPrivate();
PublicKey pubKey = kp.getPublic();
System.out.println(privKey.toString());
System.out.println(pubKey.toString());
}
}
[2] This is the code for elliptic curve cryptography for public and private key generation but when I executed this code ,showing only the public key but not the private key,so please help me out and let me know ,what to do to generate the private key!! [2]这是用于生成公钥和私钥的椭圆曲线密码的代码,但是当我执行此代码时,仅显示公钥而不显示私钥,因此请帮助我,让我知道,该怎么做私钥!!
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.ECGenParameterSpec;
public class ECCKeyGeneration {
public static void main(String[] args) {
try {
KeyPairGenerator kpg;
kpg = KeyPairGenerator.getInstance("EC","SunEC");
ECGenParameterSpec ecsp;
ecsp = new ECGenParameterSpec("secp192r1");
kpg.initialize(ecsp);
KeyPair kp = kpg.genKeyPair();
PrivateKey privKey = kp.getPrivate();
PublicKey pubKey = kp.getPublic();
System.out.println(privKey.toString());
System.out.println(pubKey.toString());
} catch (Exception ex) {
System.out.println(ex);
}
}
}
I've just tested the above code. 我刚刚测试了上面的代码。
Output 输出量
Sun EC private key, 192 bits private value: 3248833611418544793834748156439256292267803494576663573112
Sun EC私钥,192位私有值:324883361141854474473473471156156256292267803494576663573112
parameters: secp192r1 [NIST P-192, X9.62 prime192v1] (1.2.840.10045.3.1.1) Sun EC public key, 192 bits public x coord: 5122655651118956061783347731888893733494103991283417332818 public y coord: 223043343028867724454216740788693823451155477884918709166参数:secp192r1 [NIST P-192,X9.62 prime192v1](1.2.840.10045.3.1.1) Sun EC公钥,192位 public x坐标:5122655651118956061783341881883733494104103991283417332818 public y坐标:223043343028867724454216740788693823451
parameters: secp192r1 [NIST P-192, X9.62 prime192v1] (1.2.840.10045.3.1.1)参数:secp192r1 [NIST P-192,X9.62 prime192v1](1.2.840.10045.3.1.1)
Are you getting the same output? 您得到相同的输出吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.