MD5 Encryption in .NET/.NET Core

Enviroment

  • .NET Core 2.1

References

Step

To acheive the encryption purpose, all we need to do is copy&paste. Usage is written in the MSDN page I posted above.

public class Encryption {
    private MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();

    public string Encrypt(string key)
    {
        byte[] data = md5.ComputeHash(Encoding.Default.GetBytes(key));
        StringBuilder sBuilder = new StringBuilder();
        for (int i = 0; i < data.Length; i++)
        {
            sBuilder.Append(data[i].ToString("x2"));
        }

        return sBuilder.ToString();
    }
}

I wrote it as a standalone module in my project, it’s easier to modify/add things in the future.

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据