⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dhparametersgenerator.java

📁 bouncycastle 是一个JAVA安全提供者
💻 JAVA
字号:
package org.bouncycastle.crypto.generators;import java.math.BigInteger;import java.security.SecureRandom;import org.bouncycastle.crypto.params.DHParameters;public class DHParametersGenerator{    private int             size;    private int             certainty;    private SecureRandom    random;    private static BigInteger ONE = BigInteger.valueOf(1);    private static BigInteger TWO = BigInteger.valueOf(2);    /**     * Initialise the parameters generator.     *      * @param size bit length for the prime p     * @param certainty level of certainty for the prime number tests     * @param random  a source of randomness     */    public void init(        int             size,        int             certainty,        SecureRandom    random)    {        this.size = size;        this.certainty = certainty;        this.random = random;    }    /**     * which generates the p and g values from the given parameters,     * returning the DHParameters object.     * <p>     * Note: can take a while...     */    public DHParameters generateParameters()    {        BigInteger      g, p, q;        int             qLength = size - 1;        //        // find a safe prime p where p = 2*q + 1, where p and q are prime.        //        for (;;)        {            q = new BigInteger(qLength, certainty, random);            p = q.multiply(TWO).add(ONE);            if (p.isProbablePrime(certainty))            {                break;            }        }        //        // calculate the generator g - the advantage of using the 2q+1         // approach is that we know the prime factorisation of (p - 1)...        //        for (;;)        {            g = new BigInteger(qLength, random);            if (g.modPow(TWO, p).equals(ONE))            {                continue;            }            if (g.modPow(q, p).equals(ONE))            {                continue;            }            break;        }        return new DHParameters(p, g, q, 2);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -