title: Encrypt password C# Decrypt Node.js
body: <p>I have a desktop application made in <strong>C#</strong>, and a web application with <strong>node.js</strong>. In the <strong>C#</strong> application I create users and from the web I have to login with those users. What I want is to <strong>encrypt</strong> the <strong>password</strong> from the c # app and save it to sql server and when the web client logs in that their password is encrypted and compared with the password from the database.</p>
  
  <p>I've followed several tutorials, but I can not figure out how to do this.</p>
  
  <p>What I have achieved so far is to save the password as bytes in the c # application but I do not know how to convert it to string and uncrypt it in node.js</p>
  
  <p>I have also been able to encrypt the password in the web application as follows:</p>
  
  <pre><code>var key = CryptoJS.enc.Utf8.parse('8080808080808080');
  var iv = CryptoJS.enc.Utf8.parse('8080808080808080');
  
    var encryptedpassword = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse($('#input_password').val()), key, {
        keySize: 128 / 8,
        iv: iv,
        mode: CryptoJS.mode.CBC,
        padding: CryptoJS.pad.Pkcs7
    });
  </code></pre>
  
  <p>Crypt password in c#:</p>
  
  <pre><code>    public static byte[] EncryptStringToBytes(string plainText, byte[] key, byte[] iv) {
  
        // Check arguments.
        if (plainText == null || plainText.Length &lt;= 0) {
          throw new ArgumentNullException("plainText");
        }
        if (key == null || key.Length &lt;= 0) {
          throw new ArgumentNullException("key");
        }
        if (iv == null || iv.Length &lt;= 0) {
          throw new ArgumentNullException("key");
        }
        byte[] encrypted;
        // Create a RijndaelManaged object
        // with the specified key and IV.
        using (var rijAlg = new RijndaelManaged()) {
          rijAlg.Mode = CipherMode.CBC;
          rijAlg.Padding = PaddingMode.PKCS7;
          rijAlg.FeedbackSize = 128;
  
          rijAlg.Key = key;
          rijAlg.IV = iv;
  
          // Create a decrytor to perform the stream transform.
          var encryptor = rijAlg.CreateEncryptor(rijAlg.Key, rijAlg.IV);
  
          // Create the streams used for encryption.
          using (var msEncrypt = new MemoryStream()) {
            using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) {
              using (var swEncrypt = new StreamWriter(csEncrypt)) {
                //Write all data to the stream.
                swEncrypt.Write(plainText);
              }
              encrypted = msEncrypt.ToArray();
            }
          }
        }
  
        // Return the encrypted bytes from the memory stream.
        return encrypted;
      }
  </code></pre>
  
  <p>Encrypt password and save in sql server:   </p>
  
  <pre><code>  Byte keybytes = Encoding.UTF8.GetBytes("8080808080808080");
    var iv = Encoding.UTF8.GetBytes("8080808080808080");
    user.password = AESEncrytDecry.EncryptStringToBytes(textEditPassword.Text, keybytes, iv);
  //... save in sql
  </code></pre>
  
  <p>Can someone explain to me how to do this process?</p>