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

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

    namespace MD51X
    {
        class MD
        {
            private string sString;
            public MD(string text)
            {
                sString=text;
            }
            /// <summary>
            /// MD5算法算出的字符串
            /// </summary>
            /// <returns>算出的字符串</returns>
            public string ToString()
            {
                return getMd5Hash(sString);
            }      
            private string getMd5Hash(string input)
            {
                MD5 md5Hasher = MD5.Create();

                byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));

                StringBuilder sBuilder = new StringBuilder();

                for (int i = 0; i < data.Length; i++)
                {
                    sBuilder.Append(data[i].ToString("x2"));
                }
                return sBuilder.ToString();
            }
        }
    }

    上面的是MD5加密的类(一定要加这个命名空间:using System.Security.Cryptography;)

    下面是主程序

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace MD51X
    {
        class Program
        {
            static void Main(string[] args)
            {
               
                Console.WriteLine("请输入,加密字符串");
                string pwd = Console.ReadLine();
                string Md5password = (new MD(pwd)).ToString();
                Console.WriteLine("输出加密后的字符");
                Console.WriteLine(Md5password);
                Console.ReadLine();
            }
        }
    }

    下面试运算结果

  • 相关阅读:
    [Axiom 3D]1.初识Axiom
    [.Net]System.OutOfMemoryException异常
    一个恶心的需求
    度分秒的正则表达式
    CSLA.Net学习(3)INotifyPropertyChanged和IDataErrorInfo
    [转载]高斯正反算
    分带?不分带?
    chm帮助文档制作及C#调用
    OleDb未指定错误
    [学习笔记]工厂方法用于数据库开发
  • 原文地址:https://www.cnblogs.com/gouguo/p/2707433.html
Copyright © 2011-2022 走看看