Elight.Utility/Security/MD5Helper.cs

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

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

namespace Elight.Utility.Security
{
    public static class MD5Helper
    {
        /// <summary>
        /// 字符串MD5加密。
        /// </summary>
        /// <param name="strOri">需要加密的字符串</param>
        /// <returns></returns>
        public static string md5(this string text)
        {
            return md5(text, Encoding.Default);
        }
        public static string MD5(this string text)
        {
            return MD5(text, Encoding.Default);
        }
        /// <summary>
        /// 字符串MD5加密。
        /// </summary>
        /// <param name="strOri">需要加密的字符串</param>
        /// <returns></returns>
        public static string md5(this string text, Encoding encoder)
        {
            // Create a new instance of the MD5CryptoServiceProvider object.
            System.Security.Cryptography.MD5 md5Hasher = System.Security.Cryptography.MD5.Create();
            // Convert the input string to a byte array and compute the hash.
            byte[] data = md5Hasher.ComputeHash(encoder.GetBytes(text));
            // Create a new Stringbuilder to collect the bytes
            // and create a string.
            StringBuilder sBuilder = new StringBuilder();
            // Loop through each byte of the hashed data 
            // and format each one as a hexadecimal string.
            for (int i = 0; i < data.Length; i++)
            {
                sBuilder.Append(data[i].ToString("x2"));
            }
            // Return the hexadecimal string.
            return sBuilder.ToString().ToLower();
        }
        public static string MD5(this string text, Encoding encoder)
        {
            return md5(text, encoder).ToUpper();
        }
        /// <summary>
        /// 文件流MD5加密。
        /// </summary>
        /// <param name="stream">需要加密的文件流</param>
        /// <returns></returns>
        public static string md5(this Stream stream)
        {
            MD5 md5serv = MD5CryptoServiceProvider.Create();
            byte[] buffer = md5serv.ComputeHash(stream);
            StringBuilder sb = new StringBuilder();
            foreach (byte var in buffer)
            {
后面还有 53 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。