i need a sample of Hash SHA512 with string value in c sharp for c sharp website
how to create Hash SHA512 of a string in c #
Collapse
X
-
Here is a method I use regularly to create a SHA512 of a string
Code:public static string SHA512(string plainText, byte[] saltBytes) { if (saltBytes == null) { int minSalt = 4; int maxSalt = 8; rnd rnd = new rnd(); int saltSize = rnd.Next(minSalt, maxSalt); saltBytes = new byte[saltSize]; RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); rng.GetNonZeroBytes(saltBytes); } byte[] bytes = Encoding.UTF8.GetBytes(plainText); byte[] textWithSaltBytes = new byte[bytes.Length + saltBytes.Length]; for (int i = 0; i < bytes.Length; i++) { textWithSaltBytes[i] = bytes[i]; } for (int i = 0; i < saltBytes.Length; i++) { textWithSaltBytes[bytes.Length + i] = saltBytes[i]; } hshAlgorithm hsh; hsh = new SHA512Managed(); byte[] hshBytes = hsh.Computehsh(textWithSaltBytes); byte[] hshWithSaltBytes = new byte[hshBytes.Length + saltBytes.Length]; for (int i = 0; i < hshBytes.Length; i++) { hshWithSaltBytes[i] = hshBytes[i]; } for (int i = 0; i < saltBytes.Length; i++) { hshWithSaltBytes[hshBytes.Length + i] = saltBytes[i]; } string hshValue = Convert.ToBase64String(hshWithSaltBytes); return hshValue; }Comment
Comment