开发者

Diffie-Hellman set generator parameter in BouncyCastle

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

DHParameter ::= SEQUENCE {
    p开发者_运维知识库rime INTEGER, -- p
    base INTEGER, -- g
    privateValueLength INTEGER OPTIONAL
}

using BouncyCastle. My current code

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.


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


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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜