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

     //MD5特殊加密
            public static string MD51(string password)
            {
                string strResult = ""
                MD5 md5 = System.Security.Cryptography.MD5.Create();
                byte[] byteresult = md5.ComputeHash(Encoding.UTF8.GetBytes(password));
                for (int i = 0; i < byteresult.Length; i++)
                {
                    strResult += byteresult[i].ToString();

                }
                return strResult;
            }

            public static string Get_MD5_Method1(string strSource)
            {
                //new
                MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
                //获取密文字节数组
                byte[] bytResult = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(strSource));

                //转换成字符串,并取9到25位
               
                string strResult = BitConverter.ToString(bytResult, 4, 8);
                //转换成字符串,32位
                //string strResult = BitConverter.ToString(bytResult);

                //BitConverter转换出来的字符串会在每个字符中间产生一个分隔符,需要去除掉
                strResult = strResult.Replace("-""");
                return strResult;
            }
            //SHA1加密
            public static string EncryptPassword(string password) 
            {
                string s="";
                UnicodeEncoding encoding = new UnicodeEncoding();
                byte[] hashBytes = encoding.GetBytes(password);
                SHA1 sha1 = new SHA1CryptoServiceProvider();
                byte[] cryptPassWord = sha1.ComputeHash(hashBytes);
                for (int i = 0; i < cryptPassWord.Length; i++)
                {
                    s += cryptPassWord[i].ToString();
                }
                    return s;
            }
  • 相关阅读:
    thinkphp nginx 上配置 并解决get获取到数据现象
    Linux下压缩某个文件夹(文件夹打包)
    Nginx下实现pathinfo及ThinkPHP的URL Rewrite模式支持
    SecureCRT超级终端使用说明
    redis 中文文档
    【Spring学习笔记-MVC-15】Spring MVC之异常处理
    【Spring学习笔记-MVC-14】Spring MVC对静态资源的访问
    【Spring学习笔记-MVC-13.2】Spring MVC之多文件上传
    【Spring学习笔记-MVC-13】Spring MVC之文件上传
    【Spring学习笔记-MVC-12】Spring MVC视图解析器之ResourceBundleViewResolver
  • 原文地址:https://www.cnblogs.com/houziwty/p/2215443.html
Copyright © 2011-2022 走看看