zoukankan      html  css  js  c++  java
  • ASP.net和C#的MD5加密

    C#:

    using System.Security;
    using System.Security.Cryptography;
    using System.Security.Authentication;

    static string UserMd5(string str)
            {

               
    string pwd = "";
                MD5 md5
    = MD5.Create();//实例化一个md5对像
               
    // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择 
                byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
               
    // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
                for (int i = 0; i < s.Length; i++)
                {
                   
    // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符

                    pwd
    = pwd + s[i].ToString("X");

                }
               
    return pwd;

            }

    ASP.net:

    using System.Web.Security;

    password = FormsAuthentication.HashPasswordForStoringInConfigFile(edtPwd.Text, "md5");

    password = FormsAuthentication.HashPasswordForStoringInConfigFile(edtPwd.Text, "sha1");

     

  • 相关阅读:
    anltr 解析MYSQL
    MYSQL 主从复制
    Java happens-before
    傅里叶分析-数据通信的理论基础
    Java jdk常用工具集合
    kafka报错 日志压缩报错直接退出
    linux centos7开启防火墙端口
    mysql_取分组后的前几行值
    数据库隔离级别
    mysql删除重复数据
  • 原文地址:https://www.cnblogs.com/fhuafeng/p/2703987.html
Copyright © 2011-2022 走看看