【发布时间】:2015-05-18 12:13:15
【问题描述】:
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] 这是用于生成公钥和私钥的椭圆曲线密码学的代码,但是当我执行此代码时,只显示公钥而不显示私钥,所以请帮帮我,让我知道该怎么做生成私钥!!
【问题讨论】:
-
编写生成私钥的代码?由于我们不知道该代码的作用,我们不知道类,我们可以假设 getPrivate() 的实现类似于:return "";
-
@Stultuske 请冷静...
KeyPair是一个标准的java对象...检查一下here -
另找here方法
getPrivate() -
执行时显示 --> Main.java:4: error: class ECCKeyGeneration is public, 应在名为 ECCKeyGeneration.java 的文件中声明 public class ECCKeyGeneration { ^ 1 error //so what to怎么办??
-
将您的文件命名为 ECCKeyGeneration.java,并带有 try catch 块。然后编译并运行文件。我试过你的代码,它可以工作并提供私钥和公钥。
标签: java elliptic-curve