在生成 DH 参数时,我在使用 Bouncy Castle Provider 时遇到了一些性能问题。任何人都知道为什么下面的 Bouncy Castle 示例比使用标准提供程序慢约 50 倍?
使用 Bouncy Castle 提供程序:
Security.addProvider(new BouncyCastleProvider());
AlgorithmParameterGenerator generator = AlgorithmParameterGenerator.getInstance("DH", "BC");
for (int i = 0; i < 3; i++) {
generator.init(1024, new SecureRandom());
AlgorithmParameters params = generator.generateParameters();
DHParameterSpec dhSpec = (DHParameterSpec) params.getParameterSpec(DHParameterSpec.class);
System.out.println("P: " + dhSpec.getP() + ", G:" + dhSpec.getG());
}
使用标准提供者:
AlgorithmParameterGenerator generator = AlgorithmParameterGenerator.getInstance("DH");
for (int i = 0; i < 3; i++) {
generator.init(1024, new SecureRandom());
AlgorithmParameters params = generator.generateParameters();
DHParameterSpec dhSpec = (DHParameterSpec) params.getParameterSpec(DHParameterSpec.class);
System.out.println("P: " + dhSpec.getP() + ", G:" + dhSpec.getG());
}