【发布时间】:2019-12-06 23:28:14
【问题描述】:
我正在尝试使用 JDK 中的 SunEC 提供程序生成 ECC 密钥对。
这是我的代码:
String name = paceInfo.getDomainName();
KeyPairGenerator kpg = null;
try {
kpg = KeyPairGenerator.getInstance("EC");
} catch (NoSuchAlgorithmException e) {
LOG.error("Unsupported Algorithm for KeyPairGenerator : EC - Exception : " + e.getMessage());
return;
}
ECGenParameterSpec ecps = new ECGenParameterSpec(name);
try {
kpg.initialize(ecps);
} catch (InvalidAlgorithmParameterException e) {
LOG.error("KeyPairGenerator initialization failed. ECGenParameterSpec : " + ecps.getName() + " - Exception : " + e.getMessage());
return;
}
KeyPair kp = kpg.generateKeyPair();
paceInfo.getDomainName() 返回一个字符串,其中包含我要使用的指定曲线的名称。在这种情况下,“brainpoolP256r1”。
我检查了在调用 KeyPairGenerator.getInstance("EC") 时选择了 SunEC 提供程序,并且该提供程序支持指定的曲线。
当我运行此代码时,我收到以下错误:
Caused by: java.security.InvalidAlgorithmParameterException
at sun.security.ec.ECKeyPairGenerator.generateECKeyPair(Native Method)
at sun.security.ec.ECKeyPairGenerator.generateKeyPair(ECKeyPairGenerator.java:128)
我试图找出这段代码有什么问题。 我正在使用 Java 8 (JDK 8u192) 和 Eclipse 2018-09。
我做错了什么吗?如果有人可以提供帮助,将不胜感激。
谢谢
【问题讨论】:
-
那个字符串名称是什么=paceInfo.getDomainName();这个字符串的值是多少?
-
@Sambit
The paceInfo.getDomainName() returns a String that contains the name of the specified curve I want to use. In this case, "brainpoolP256r1".他写得很清楚。你读过他的问题吗?
标签: java java-8 cryptography provider elliptic-curve