0

I have below function in c# for encryption.

public static string Encrypt(string str)
{
    string EncrptKey = "2013;[pnuLIT)WebCodeExpert";
    byte[] byKey = { };
    byte[] IV = { 18, 52, 86, 120, 144, 171, 205, 239 };
    byKey = System.Text.Encoding.UTF8.GetBytes(EncrptKey.Substring(0, 8));
    DESCryptoServiceProvider des = new DESCryptoServiceProvider();
    byte[] inputByteArray = Encoding.UTF8.GetBytes(str);
    MemoryStream ms = new MemoryStream();
    CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
    cs.Write(inputByteArray, 0, inputByteArray.Length);
    cs.FlushFinalBlock();
    return Convert.ToBase64String(ms.ToArray());
}

I want to use same methodology in node.js for encryption. Any help would be appreciated.

Kishor
  • 356
  • 2
  • 11
  • You compile the C# as a web method and call the web method from node.js – Nick.Mc Jul 01 '18 at 11:36
  • *I want to use same methodology in node.js for encryption* - what did you try and what exactly did go wrong? – Estus Flask Jul 01 '18 at 12:08
  • 1
    You should only use DES if you have a specific reason to use DES, the keyspace is too small to be considered secure. AES is a superior alternative: https://stackoverflow.com/questions/202011/encrypt-and-decrypt-a-string-in-c/10366194#10366194 – Alex K. Jul 01 '18 at 12:17

0 Answers0