node.js rsa加密/解密

时间:2013-09-11 10:47:55

标签: javascript node.js rsa crypt

我有以下C#代码:

// incoming data - MemoryStream memoryStream
RSACryptoServiceProvider cryptoServiceProvider1 = new RSACryptoServiceProvider();
cryptoServiceProvider1.FromXmlString("<RSAKeyValue><Modulus>...</Modulus><Exponent>AQAB</Exponent><P>...</P><Q>...</Q><DP>...</DP><DQ>...</DQ><InverseQ>...</InverseQ><D>...</D></RSAKeyValue>");
cryptoServiceProvider1.PersistKeyInCsp = true;
RijndaelManaged rijndaelManaged = new RijndaelManaged();
rijndaelManaged.KeySize = 256;
rijndaelManaged.BlockSize = 128;
rijndaelManaged.Mode = CipherMode.CBC;
byte[] numArray3 = new byte[128];
byte[] numArray4 = new byte[16];
// numArray3 & numArray4 - filled with come data;
byte[] rgbKey = cryptoServiceProvider1.Decrypt(numArray3, false);
ICryptoTransform decryptor = rijndaelManaged.CreateDecryptor(rgbKey, numArray4);
CryptoStream cryptoStream = new CryptoStream((Stream) memoryStream, decryptor, CryptoStreamMode.Write);

问题:是否可以将此功能迁移到node.js(javascript)?

1 个答案:

答案 0 :(得分:1)

我非常确定this节点模块将能够做你想做的事。

  

此Node模块为OpenSSL的RSA公钥/私钥加密功能提供了一套相当完整的包装器。

请查看this answer,了解将XML密钥转换为可由Node模块使用的标准PEM密钥的可能方法。