简体   繁体   English

来自JavaScript中的模数和私有指数的RSA私钥

[英]RSA private key from modulus and private exponent in JavaScript

I have a modulus and private exponent. 我有一个模数和私有指数。 How can I generate an RSA private Key in JavaScript from that? 如何从中生成JavaScript中的RSA私钥?

Or if these values are not enough to generate a RSA private Key. 或者,如果这些值不足以生成RSA私钥。 What are the other values that I might possibly need. 我可能需要的其他值是什么?

RSAPrivateKeySpec in Java 7 is able to generate RSA private key with mod and private Exp. Java 7中的RSAPrivateKeySpec能够使用mod和private Exp生成RSA私钥。 I'm looking for a equivalent in JavaScript. 我正在寻找JavaScript中的等价物。

I also tried npm ursa module which unfortunately didn't work out. 我也尝试了npm ursa模块,遗憾的是没有成功。

JSBN is able to create an RSA private key which can decrypt. JSBN能够创建可以解密的RSA私钥。

var sk = new RSAKey();
sk.setPrivate("<modulus hex>", "<public exponent hex>", "<private exponent hex>");
var plaintext = sk.decrypt("<ciphertext hex>");

The public exponent is not used during decryption, so you can simply pass some garbage hex into it, but it's either "03" (3), "11" (17) or "010001" (65537). 在解密期间不使用公共指数,因此您可以简单地将一些垃圾十六进制传递给它,但它是“03”(3),“11”(17)或“010001”(65537)。

You'd need to include jsbn.js, jsbn2.js, rsa.js, and rsa2.js. 你需要包括jsbn.js,jsbn2.js,rsa.js和rsa2.js. Keep in mind that decryption will be 4 times slower than with a full RSA key, because the Chinese Remainder Theorem cannot be used. 请记住,解密将比使用完整RSA密钥慢4倍,因为无法使用中国剩余定理。

The modulus and private exponent are , technically, enough to generate an RSA private key, abstractly ; 模数和私人指数 ,在技术上,足以产生一个RSA私钥, 抽象 ; they're only insufficient to generate an RSA private key with its inputs , as used to optimize decryption using the Chinese remainder theorem . 它们仅仅不足以用其输入生成RSA私钥,用于使用中国剩余定理来优化解密。 ( As Artjom B.'s answer notes , some implementations are able to perform this non-optimized decryption; however, some are not.) 正如Artjom B.的回答所说 ,一些实现能够执行这种非优化的解密;但是,有些不是。)

To create a full RSA private key, with its inputs as used for optimization, you need the original primes p and q . 要创建完整的 RSA私钥,并使用其用于优化的输入,您需要原始质数pq There's no simple, deterministic way to obtain these from the modulus and private exponent, but methods exist to search for them in a space small enough to be tractable. 没有简单,确定的方法从模数和私有指数中获得这些,但是存在在足够小的空间中搜索它们以便易于处理的方法。 See the answers to this question: Calculate primes p and q from private exponent (d), public exponent (e) and the modulus (n) 请参阅此问题的答案: 从私有指数(d),公共指数(e)和模数(n)计算素数p和q

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM