private static BigInteger generatePrime( int bitLength, int certainty, SecureRandom rand) { BigInteger p_ = BigIntegers.createRandomPrime(bitLength, certainty, rand); while (p_.bitLength() != bitLength) { p_ = BigIntegers.createRandomPrime(bitLength, certainty, rand); } return p_; }
static BigInteger[] generateSafePrimes(int size, int certainty, SecureRandom random) { BigInteger p, q; int qLength = size - 1; for (; ; ) { q = BigIntegers.createRandomPrime(qLength, 2, random); p = q.shiftLeft(1).add(ONE); if (p.isProbablePrime(certainty) && (certainty <= 2 || q.isProbablePrime(certainty))) { break; } } return new BigInteger[]{p, q}; }
BigInteger p = BigIntegers.createRandomPrime(bitlength, 1, param.getRandom());
q = BigIntegers.createRandomPrime(qLength, 2, random);
g = BigIntegers.createRandomPrime(strength, certainty, rand); if (g.modPow(e, n).equals(ONE))