我使用Key和IV使用RSC2-cbc算法在C#中使用现有的加密和解密登录.现在我将在node.js中实现相同的功能.所以我写了以下代码来加密和解密.我面临的问题是node.js加密字符串(chiper)或解密字符串与C#encryptrd字符串不匹配.
现有的C#代码
byte[] arrbIV = Encoding.ASCII.GetBytes("dleftaba");
byte[] arrbKey = Encoding.ASCII.GetBytes(Key);
byte[] arrbData = Encoding.ASCII.GetBytes(sData); //Text to be encryptrd
RC2 oEncryptor = new RC2CryptoServiceProvider();
oEncryptor.Mode = CipherMode.CBC;
oEncryptor.Key = arrbKey;
oEncryptor.IV = arrbIV;
// Create memory stream to store encrypted string
MemoryStream oMemoryStream = new MemoryStream();
CryptoStream oCryptoStream = new CryptoStream(oMemoryStream, oEncryptor.CreateEncryptor(),
CryptoStreamMode.Write);
// Peform the encryption
oCryptoStream.Write(arrbData, 0, arrbData.Length);
// We have written all the data in the stream and now we can apply padding
oCryptoStream.Close();
string sRetVal = Convert.ToBase64String(oMemoryStream.ToArray()); …Run Code Online (Sandbox Code Playgroud)