【问题标题】:Getting Runtime Exception when using generateKeyPair from SunEC provider使用 SunEC 提供程序的 generateKeyPair 时出现运行时异常
【发布时间】: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


【解决方案1】:

来自ticket on Oracle bugs site 在 Java 11 中为 SunEC 添加/修复了对 Brainpool 曲线的支持,因此它可用于 Java 11+。

【讨论】:

  • 非常感谢,通过我的研究没有找到这张票。它解释了为什么它不工作。
  • 刚刚用 Java 11 测试过,它可以工作,对于 Java 8 就不行。
  • 您始终可以使用 BouncyCastle 库作为加密提供者,它可能支持脑池曲线。
  • 是的,我想我会选择 BouncyCastle。我试图避免它,但似乎我不能。感谢您的帮助。
  • FWIW,BouncyCastle 支持 BrainpoolP256r1
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-11
  • 2021-05-29
  • 1970-01-01
相关资源
最近更新 更多