基于http://www.win.tue.nl/pinpasjc/docs/apis/jc222/javacard/security/RSAPrivateCrtKey.html我可以获得:
- P,质因数p
- Q,质因数 q
- PQ = q-1 mod p
- DP1 = d mod (p - 1)
- DQ1 = d mod (q - 1)
通过调用每个 getter。但是,我如何获得私有(private)指数“d”?我应该手动计算私有(private)指数“d”,还是有任何简单的方法可以从 RSAPrivateCrtKey 获取私有(private)指数“d”? 反正只是为了锻炼一下,不会有什么坏处。
编辑: 我确实需要私有(private)指数“d”来从 XML 生成 PEM 文件。仅供引用,这只是一个练习,我只是想证明 Java Card 中的 RSAPrivateCrtKey 与现实世界中的 RSAPrivateCrtKey 相同(如 OpenSSL 等)。还有其他方法可以证明吗?或者,是否有其他方法可以从 RSAPrivateCrtKey 制作没有私有(private)指数“d”的 PEM 文件?
最佳答案
这个应该可以工作(源自 Bouncy CaSTLe 的 RSAKeyPairGenerator.java 并使用一个 RSA 私钥进行验证):
public static BigInteger getPrivateExponent(byte[] publicExponentBytes, byte[] pBytes, byte[] qBytes) {
BigInteger e = new BigInteger(1, publicExponentBytes);
BigInteger p = new BigInteger(1, pBytes);
BigInteger q = new BigInteger(1, qBytes);
BigInteger pSub1 = p.subtract(BigInteger.ONE);
BigInteger qSub1 = q.subtract(BigInteger.ONE);
BigInteger phi = pSub1.multiply(qSub1);
return e.modInverse(phi);
}
祝你好运!
关于Java 卡 RSAPrivateCrtKey 私有(private)指数 "d",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34142666/