简体   繁体   English

如何在节点js中创建密钥对象?

[英]How to create a Key Object in node js?

I´ve been trying for the last few days to Decrypt RSA base64 strings in node. 最近几天,我一直在尝试在节点中解密RSA base64字符串。 But most of the modules are poorly documented or I´m missing something. 但是大多数模块的文档记录不充分,或者我缺少一些东西。 The problem is that the private key is passphrase protected and therefore to use crypto.privateDecrypt(private_key, buffer) the key is needed to be inserted as an object. 问题在于私钥受密码保护,因此要使用crypto.privateDecrypt(private_key,buffer),需要将密钥作为对象插入。

private_key can be an object or a string. private_key可以是对象或字符串。 If private_key is a string, it is treated as the key with no passphrase and will use RSA_PKCS1_OAEP_PADDING. 如果private_key是字符串,则将其视为没有密码短语的密钥,并将使用RSA_PKCS1_OAEP_PADDING。 If private_key is an object, it is interpreted as a hash object with the keys: 如果private_key是一个对象,则将其解释为带有键的哈希对象:

key : <String> - PEM encoded private key
passphrase : <String> - Optional passphrase for the private key
padding : An optional padding value, one of the following:
crypto.constants.RSA_NO_PADDING
crypto.constants.RSA_PKCS1_PADDING
crypto.constants.RSA_PKCS1_OAEP_PADDING

All paddings are defined in crypto.constants. 所有填充都在crypto.constants中定义。

Since node js is not my native framework, is anyone kind enough to tell me how said object is created ? 由于node js不是我的本机框架,所以有人可以告诉我如何创建所述对象吗? I already have the PEM string and the passphrase needed. 我已经有了PEM字符串和所需的密码。

Thanks in advance. 提前致谢。

Nodejs is not really a framework, more a Javascript engine... Nodejs并不是一个真正的框架,而是一个Javascript引擎...
I guess you can use pure Javascript here: 我想您可以在这里使用纯Javascript:

private_key = {
    key: 'PEM encoded private key',
    passphrase: 'Optional passphrase for the private key',
    padding: crypto.constants.RSA_PKCS1_OAEP_PADDING
}

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

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