Encrypting a string using the MD5 algorithm

using System.Security.Cryptography;
 
public static string EncodePassword(string originalPassword)
{
    Byte[] originalBytes;
    Byte[] encodedBytes;
    MD5 md5;
 
    // Conver the original password to bytes; then create the hash
    md5 = new MD5CryptoServiceProvider();
    originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword);
    encodedBytes = md5.ComputeHash(originalBytes);
 
    // Bytes to string
    return System.Text.RegularExpressions.Regex.Replace(BitConverter.ToString(encodedBytes), "-", "").ToLower();
}

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top