Diffie-Hellman在BouncyCastle中设置生成器参数

时间:2022-11-06 19:12:00

I want to generate new DH parameter as defined in PKCS #3:

我想生成PKCS#3中定义的新DH参数:

DHParameter ::= SEQUENCE {
    prime INTEGER, -- p
    base INTEGER, -- g
    privateValueLength INTEGER OPTIONAL
}

using BouncyCastle. My current code

使用BouncyCastle。我目前的代码

DHParametersGenerator generator = new DHParametersGenerator();  
generator.init(2048, DEFAULT_PRIME_CERTAINTY, new SecureRandom());
DHParameters params = generator.generateParameters();

works fine, but I can't see a way to set the base on my own other than modifying the library. Is there some workaround I am missing?

工作正常,但除了修改库之外,我无法看到自己设置基础的方法。我缺少一些解决方法吗?

Thanks in advance.

提前致谢。

2 个解决方案

#1


0  

Actually, most DH implementations uses predefined base value, so it can be no way for doing that without sources modifications.

实际上,大多数DH实现都使用预定义的基本值,因此如果没有源代码修改,就无法做到这一点。

#2


0  

Actually you can set the base of your choice using the same class. So your code will become:-

实际上,您可以使用相同的类设置您选择的基础。所以你的代码将成为: -

DHParametersGenerator generator = new DHParametersGenerator();  
generator.init(2048, DEFAULT_PRIME_CERTAINTY, new SecureRandom());
DHParameters params = generator.generateParameters();
DHParameters realParams = new DHParameters(params.getP(), BigInteger.valueOf(2));

#1


0  

Actually, most DH implementations uses predefined base value, so it can be no way for doing that without sources modifications.

实际上,大多数DH实现都使用预定义的基本值,因此如果没有源代码修改,就无法做到这一点。

#2


0  

Actually you can set the base of your choice using the same class. So your code will become:-

实际上,您可以使用相同的类设置您选择的基础。所以你的代码将成为: -

DHParametersGenerator generator = new DHParametersGenerator();  
generator.init(2048, DEFAULT_PRIME_CERTAINTY, new SecureRandom());
DHParameters params = generator.generateParameters();
DHParameters realParams = new DHParameters(params.getP(), BigInteger.valueOf(2));

相关文章