Calculate the Hash Code of a Password - CSharp Security

CSharp examples for Security:Hash

Description

Calculate the Hash Code of a Password

Demo Code


using System;//from ww w.j a  v  a  2 s  .c  o  m
using System.Text;
using System.Security.Cryptography;

class MainClass
    {
        public static void Main(string[] args)
        {
            HashAlgorithm hashAlg = null;
            if (args[0].CompareTo("SHAManaged1") == 0)
            {
                hashAlg = new SHA1Managed();
            }
            else
            {
                hashAlg = HashAlgorithm.Create(args[0]);
            }

            using (hashAlg)
            {
                byte[] pwordData = Encoding.Default.GetBytes(args[1]);

                byte[] hash = hashAlg.ComputeHash(pwordData);

                Console.WriteLine(BitConverter.ToString(hash));

            }
        }
    }

Result


Related Tutorials