📄 rsakeypairgenerator.java
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi
// Source File Name: RSAKeyPairGenerator.java
package jit.crypto.generators;
import jit.crypto.*;
import jit.crypto.params.*;
import jit.math.BigInteger;
public class RSAKeyPairGenerator
implements AsymmetricCipherKeyPairGenerator
{
private static BigInteger ONE = BigInteger.valueOf(1L);
private RSAKeyGenerationParameters param;
public RSAKeyPairGenerator()
{
}
public void init(KeyGenerationParameters param)
{
this.param = (RSAKeyGenerationParameters)param;
}
public AsymmetricCipherKeyPair generateKeyPair()
{
int pbitlength = (param.getStrength() + 1) / 2;
int qbitlength = param.getStrength() - pbitlength;
BigInteger e = param.getPublicExponent();
BigInteger p;
do
p = new BigInteger(pbitlength, param.getCertainty(), param.getRandom());
while(!e.gcd(p.subtract(ONE)).equals(ONE));
BigInteger q;
BigInteger n;
do
{
do
q = new BigInteger(qbitlength, param.getCertainty(), param.getRandom());
while(!e.gcd(q.subtract(ONE)).equals(ONE) || p.equals(q));
n = p.multiply(q);
if(n.bitLength() == param.getStrength())
break;
p = p.max(q);
} while(true);
BigInteger phi;
if(p.compareTo(q) < 0)
{
phi = p;
p = q;
q = phi;
}
BigInteger pSub1 = p.subtract(ONE);
BigInteger qSub1 = q.subtract(ONE);
phi = pSub1.multiply(qSub1);
BigInteger d = e.modInverse(phi);
BigInteger dP = d.remainder(pSub1);
BigInteger dQ = d.remainder(qSub1);
BigInteger qInv = q.modInverse(p);
return new AsymmetricCipherKeyPair(new RSAKeyParameters(false, n, e), new RSAPrivateCrtKeyParameters(n, e, d, p, q, dP, dQ, qInv));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -