Tuesday 23 October 2018

Looking for tips from someone with knowledge of password hashing, Node and C#

So, I have a dated system I have acquired. It was built with webforms, SQLServer etc. I can connect and query with knex, but I'm looking to build an express API using the same DB, without forcing everyone to change their passwords. I don't have a background in C#. I realize that SHA1 is not really the way to go, but is there a way to re-create this C# in Node using something like Crypto, or am I barking up the wrong tree in my thinking? Any guidance would be appreciated.​ private string EncodePassword(string pass, string salt) { //make an array byte[] numArray; //Gets an encoding for the UTF-16 format using the little endian byte order. byte[] bytes = System.Text.Encoding.Unicode.GetBytes(pass); //Converts the specified string, which encodes binary data as base-64 digits, to an equivalent 8-bit unsigned integer array. byte[] numArray1 = Convert.FromBase64String(salt); byte[] numArray2 = new byte[(int)numArray1.Length + (int)bytes.Length]; Buffer.BlockCopy(numArray1, 0, numArray2, 0, (int)numArray1.Length); Buffer.BlockCopy(bytes, 0, numArray2, (int)numArray1.Length, (int)bytes.Length); //Creates an instance of the default implementation of SHA1. System.Security.Cryptography.HashAlgorithm hashAlgorithm = System.Security.Cryptography.SHA1.Create(); //Computes the hash value for the input data. numArray = hashAlgorithm.ComputeHash(numArray2); //Converts the value of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with base-64 digits. return Convert.ToBase64String(numArray); } ​

Submitted October 23, 2018 at 08:58PM by comma84

No comments:

Post a Comment