我如何创建java.security.interfaces.RSAPrivateKey给定 RSA 的实例d,e并且n(假设为 BigIntegers)。(这里d表示私有指数、e公共指数和n=pqRSA 模数。)
我认为这真的很简单,但我在文档或互联网中找不到任何内容。
如果有任何帮助,我已经安装了 BouncyCastle。
编辑澄清:我在寻找一个实现该接口,并采取一类d,e和/或n作为参数传递给构造函数(或参数为出厂功能等),而不是创造一个新的,随机密钥或阅读的关键来自某种 PKCS* 格式的文件。
好吧,这是给定私有指数和模数(私钥所需的所有内容)构造一个的方法:
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
RSAPrivateKeySpec privateKeySpec = new RSAPrivateKeySpec(
new BigInteger("57791d5430d593164082036ad8b29fb157791d5430d593164082036ad8b29fb157791d5430d593164082036ad8b29fb157791d5430d593164082036ad8b29fb1", 16),
new BigInteger("57791d5430d593164082036ad8b29fb157791d5430d593164082036ad8b29fb157791d5430d593164082036ad8b29fb157791d5430d593164082036ad8b29fb1", 16)
);
RSAPrivateKey privateKey = (RSAPrivateKey) keyFactory.generatePrivate(privateKeySpec);
Run Code Online (Sandbox Code Playgroud)