当我尝试生成私钥RSA

时间:2017-04-28 17:23:10

标签: java algorithm rsa private-key

我有计算RSA的D(私钥)的方法。该方法使用扩展的欧几里德算法。所以有时我会得到负面的D并且我怎么能修复它? D * e mod(p-1)(q-1)= 1; 这是方法的代码

public static BigInteger extEuclid(BigInteger a, BigInteger b)
{

        BigInteger x = BigInteger.ZERO, y = BigInteger.ONE, lastx = BigInteger.ONE, lasty = BigInteger.ZERO, temp;
        while (!b.equals(BigInteger.ZERO))
        {
            BigInteger q = a.divide(b);
            BigInteger r = a.mod(b) ;
        a = b;
        b = r;

        temp = x;
        x = lastx.subtract(q.multiply(x));
        lastx = temp;

        temp = y;
        y = lasty.subtract(q.multiply(y));
        lasty = temp;
    }

    return lastx;
}


public void calcD(){
  d = extEuclid(e, fEuler);
}

0 个答案:

没有答案