zoukankan      html  css  js  c++  java
  • MD5加密

    MD5加密:对数据进行加密,不可逆,这里用于对密码进行加密

    1.MD5加密帮助类

        /// <summary>
        /// MD5加密类型(2.0新增)
        /// </summary>
        public class MD5Helper
        {
            /// <summary>
            /// 加密账号密码
            /// </summary>
            /// <param name="account">账号</param>
            /// <param name="password">密码</param>
            /// <returns>加密后的密码</returns>
            public static string EncryptPassword(string account, string password)
            {
                if (string.IsNullOrWhiteSpace(account) || string.IsNullOrWhiteSpace(password))
                {
                    return password;
                }
    
                string encryptPassword = string.Empty;
                encryptPassword = Encrypt(string.Format("{0}={1}", account, password));
                return encryptPassword;
            }
    
            /// <summary>
            /// 加密数据
            /// </summary>
            /// <param name="str">加密前数据</param>
            /// <returns>加密后数据</returns>
            public static string Encrypt(string str)
            {
                if (string.IsNullOrWhiteSpace(str))
                {
                    return string.Empty;
                }
    
                MD5 md5 = new MD5CryptoServiceProvider();
                byte[] fromData = Encoding.Unicode.GetBytes(str);
                byte[] targetData = md5.ComputeHash(fromData);
                string result = string.Empty;
                for (int i = 0; i < targetData.Length; i++)
                {
                    result += targetData[i].ToString("x");
                }
                return result;
            }
        }
    View Code

    2.调用

    string password = MD5Helper.EncryptPassword(Account, Password);
    View Code
  • 相关阅读:
    函数
    A × B problem
    求n的阶乘
    自己构建一个vector函数
    int与string的互相转化
    列一列(斐波那契数列)
    找一找
    c++大数计算模板
    JSON--js中 json字符串转对象、对象转字符串
    JSON
  • 原文地址:https://www.cnblogs.com/ywblog/p/4243296.html
Copyright © 2011-2022 走看看