• MD5加密方法


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Security.Cryptography;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApplication1
    {
    class Program
    {
    static void Main(string[] args)
    { string str1 = Console.ReadLine();

    string sr = Clas.MD5Encrypt(str1);
    Console.WriteLine(sr);

    string f = Clas.MD5(sr);
    Console.WriteLine(f);
    Console.ReadLine();

    }

    static string myMD5(string str)
    {
    string pwd = "";
    MD5 md5 = new MD5CryptoServiceProvider();
    Byte[] byt = md5.ComputeHash(Encoding.Unicode.GetBytes(str));
    for (int i = 0; i < byt.Length; i++)
    {
    pwd += byt[i].ToString("x");
    }
    return pwd;
    }
    /// <summary>
    /// MD5 加密(不可逆加密)
    /// </summary>
    /// <param name="pass">要加密的原始字串</param>
    /// <returns></returns>
    public static string MD5Encrypt(string pass)
    {
    System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
    byte[] bytResult = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(pass));
    md5.Clear();
    string strResult = BitConverter.ToString(bytResult);
    strResult = strResult.Replace("-", "");
    return strResult;
    }

    public static string MD5 (this string text)
    {
    return FormsAuthentication.HashPasswordForStoringInConfigFile (text, "md5");
    }


    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "SHA")]
    public static string SHA1 (this string text)
    {
    return FormsAuthentication.HashPasswordForStoringInConfigFile (text, "sha1");
    }

  • 相关阅读:
    random模块的随机变换
    re模块与正则表达式进阶
    面向对象整体细化
    __new__内部工作方式
    前端之CSS
    前端之HTML
    数据库
    同步异步阻塞非阻塞
    进程间的通信
    day 36(多进程)
  • 原文地址:https://www.cnblogs.com/BoYu045535/p/3682722.html
Copyright © 2020-2023  润新知