zoukankan      html  css  js  c++  java
  • 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");
    }

  • 相关阅读:
    安卓图片载入之使用universalimageloader载入圆形圆角图片
    加密散列算法——SHA-1
    图片分类器
    LeetCode——Regular Expression Matching
    LeetCode Set Matrix Zeroes
    怎样通过浏览器分析前后端交互
    Android自己定义dialog中的EditText无法弹出键盘的解决
    @Async
    @Transactional 事务
    运行报错
  • 原文地址:https://www.cnblogs.com/BoYu045535/p/3682722.html
Copyright © 2011-2022 走看看