Tolotos 61 Posted March 30, 2015 Posted March 30, 2015 (edited) Hi, can someone give me the C# code for this Java md = MessageDigest.getInstance("SHA1"); md.update(passwordBytes); md.update(saltBytes); md.digest(); Yours Tolotos Edited March 30, 2015 by Tolotos
ebr 16169 Posted March 30, 2015 Posted March 30, 2015 https://msdn.microsoft.com/en-us/library/system.security.cryptography.sha1.aspx
Tolotos 61 Posted March 30, 2015 Author Posted March 30, 2015 Hmm, there is only a ComputeHash method but how should I handle the salt?
Tolotos 61 Posted March 30, 2015 Author Posted March 30, 2015 public class SHA1helper { public static byte[] GenerateSaltedSHA1(string plainTextString, byte[] saltBytes) { HashAlgorithm algorithm = new SHA1Managed(); byte[] plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainTextString); byte[] plainTextWithSaltBytes = new byte[plainTextBytes.Length + saltBytes.Length]; for (int i = 0; i < plainTextBytes.Length; i++) { plainTextWithSaltBytes[i] = plainTextBytes[i]; } for (int i = 0; i < saltBytes.Length; i++) { plainTextWithSaltBytes[plainTextBytes.Length + i] = saltBytes[i]; } byte[] digest = algorithm.ComputeHash(plainTextWithSaltBytes); return digest; } } Did it.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now