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
  • 相关阅读:
    scp命令(基于ssh上传文件等)
    mac上安装ruby
    Access denied for user ''@'localhost' to database 'mysql'
    3.ruby语法基础,全部变量,实例变量,类变量,局部变量的使用和注意的要点
    2.ruby基本语法,类的定义
    1.ruby基本格式
    neo4j在linux下的安装
    mongodb导入json文件
    mongodb 安装启动
    Junit4
  • 原文地址:https://www.cnblogs.com/ywblog/p/4243296.html
Copyright © 2011-2022 走看看