Jump to content

SHA1 with C#


Tolotos

Recommended Posts

Tolotos

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 by Tolotos
Link to comment
Share on other sites

Tolotos

Hmm, there is only a ComputeHash method but how should I handle the salt?

Link to comment
Share on other sites

Tolotos
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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...