Here you can find the source of generateSafePrimes(int size, int certainty, SecureRandom random)
static BigInteger[] generateSafePrimes(int size, int certainty, SecureRandom random)
//package com.java2s; //License from project: LGPL import java.math.BigInteger; import java.security.SecureRandom; public class Main { private static final BigInteger ONE = BigInteger.valueOf(1); static BigInteger[] generateSafePrimes(int size, int certainty, SecureRandom random) { BigInteger p, q;//from w ww. j a v a2s .com int qLength = size - 1; for (;;) { q = new BigInteger(qLength, 2, random); // p <- 2q + 1 p = q.shiftLeft(1).add(ONE); if (p.isProbablePrime(certainty) && (certainty <= 2 || q.isProbablePrime(certainty))) { break; } } return new BigInteger[] { p, q }; } }