我有這個c#代碼來加密數據,需要node.js中的解密方法。我嘗試了node.js的加密模塊,但無法繼續。需要解密方法在節點js下面c#加密方法
private string Encrypt(string clearText)
{
string EncryptionKey = "Something";
byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);
using (Aes encryptor = Aes.Create())
{
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
encryptor.Key = pdb.GetBytes(32);
encryptor.IV = pdb.GetBytes(16);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(clearBytes, 0, clearBytes.Length);
cs.Close();
}
clearText = Convert.ToBase64String(ms.ToArray());
}
}
return clearText;
}
我已經在密碼模塊試圖
cryptogrphy.pbkdf2("Something", 'Ivan Medvedev', 1000, 128/4, function (cErr, cBuffer) {
var cKey = cBuffer.slice(0, 32);
var cIV = cBuffer.slice(0, 16);
var cDecipher = cryptogrphy.createDecipheriv("AES-128-CBC", cKey, cIV);
var sDecoded = cDecipher.update(text);
sDecoded += cDecipher.final("utf8");
console.log(sDecoded);
}); //'Ivan Medvedev' is equivalent string to salt byte in encryption method
如果需要,我可以提供C#編寫的 –