Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JS前端上的openssl命令_Javascript_Encryption_Openssl - Fatal编程技术网

Javascript JS前端上的openssl命令

Javascript JS前端上的openssl命令,javascript,encryption,openssl,Javascript,Encryption,Openssl,您好,我尝试使用crypto JS在JS上复制这些命令,但没有成功 openssl pkcs8 -inform DER -in #{file.key} -passin pass:#{password} -out myPrivate.key 通过这个,我获得了一个rsa编码的私钥,我可以使用它来计算它的模数,并将其与另一个文件进行比较 openssl rsa -in myPrivate.key -noout -modulus openssl x509 -inform DER -in certif

您好,我尝试使用crypto JS在JS上复制这些命令,但没有成功

openssl pkcs8 -inform DER -in #{file.key} -passin pass:#{password} -out myPrivate.key
通过这个,我获得了一个rsa编码的私钥,我可以使用它来计算它的模数,并将其与另一个文件进行比较

openssl rsa -in myPrivate.key -noout -modulus
openssl x509 -inform DER -in certificate.cer -noout -modulus
如果这两个的输出是相等的,那么用户是被授权的,但是我尝试在JS上复制它却没有成功,当我读取字符串上的文件并试图将它们传递给它时,它会不断抛出错误


有人能帮我一下吗?

我只是想检查一下私钥和公钥的模数是否相同,以确定用户是否被授权。也就是说,使用forge,我相信这应该满足您的要求:

function isAuthorized(privateKeyPem, password, certificatePem) {
  var privateKey = forge.pki.decryptRsaPrivateKey(
    privateKeyPem, password);

  var certificate = forge.pki.certificateFromPem(certificatePem);
  var publicKey = certificate.publicKey;

  // returns true when modulus is the same
  return privateKey.n.compareTo(publicKey.n) === 0;
}
如果您使用的是未加密的私钥,请改用此密钥(从PEM格式转换):

var privateKey = forge.pki.privateKeyFromPem(privateKeyPem);