how to encrypt string value in md5 using c#

using System;
using System.Security.Cryptography;
using System.Text;

//Name Is Use of Project Name
namespace ajayvishu
{
    public class Program
    {
        public static void Main(string[] args)
        {
           var source = "Ajay Vishwakarma!";

            // Creates an instance of the default implementation of the MD5 hash algorithm.
            using (var md5Hash = MD5.Create())
            {
                // Byte array representation of source string
                var sourceBytes = Encoding.UTF8.GetBytes(source);

                // Generate hash value(Byte Array) for input data
                var hashBytes = md5Hash.ComputeHash(sourceBytes);

                // Convert hash byte array to string
                var hash = BitConverter.ToString(hashBytes).Replace("-", string.Empty);

                // Output the MD5 hash
                Console.WriteLine("The MD5 hash of " + source + " is: " + hash);
            }
        }
    }
}

Post a Comment

0 Comments