[英]Is using the BigInteger probablePrime function safe for RSA encryption?
[英]Difference between BigInteger.probablePrime() and other primality algorithms in java
我正在使用Java實現RSA加密程序。 現在我使用BigInteger.probablePrime(1024, rnd)
來獲取素數。 這里rnd
是Random rnd = new Random()
生成的隨機數。 我需要測試各種加密速度。
我的問題是:
BigInteger.probablePrime(1024, rnd)
使用什么算法?
上面的算法與其他算法有什么區別:比如Rabin-Miller,Fermats,Lucas-Lehmer?
謝謝。
BigInteger
可能的素數方法使用Miller-Rabin和Lucas-Lehmer算法來測試素數。
請參閱內部方法BigInteger.primeToCertainty
。
Java源代碼可供下載,因此您可以自己查看。 以下是BigInteger.probablePrime(int, Random)
的代碼:
public static BigInteger probablePrime(int bitLength, Random rnd) {
if (bitLength < 2)
throw new ArithmeticException("bitLength < 2");
// The cutoff of 95 was chosen empirically for best performance
return (bitLength < SMALL_PRIME_THRESHOLD ?
smallPrime(bitLength, DEFAULT_PRIME_CERTAINTY, rnd) :
largePrime(bitLength, DEFAULT_PRIME_CERTAINTY, rnd));
}
實際測試包含在smallPrime()
和largePrime()
方法中,后者直接在源代碼中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.