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");
    }

  • 相关阅读:
    第十一周课堂测试 -- 四则运算
    软件工程第十一周学习进度
    软件工程课堂测试2
    软件工程概论_课堂测试
    11.16 动手动脑
    动手动脑
    网络模型分析
    Actor模型原理
    linux下启动oracle
    Linux 环境下Oracle11g安装图文详细教程
  • 原文地址:https://www.cnblogs.com/BoYu045535/p/3682722.html
Copyright © 2011-2022 走看看