博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MD5加密
阅读量:4599 次
发布时间:2019-06-09

本文共 1150 字,大约阅读时间需要 3 分钟。

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

下面试运算结果

转载于:https://www.cnblogs.com/gouguo/archive/2012/09/28/2707433.html

你可能感兴趣的文章
pom.xml里有红叉报错的解决办法
查看>>
Perl last和next的用法区别
查看>>
Selenium 管理 Cookies
查看>>
ZOJ 1204 一个集合能组成多少个等式
查看>>
exceptionfunction[LeetCode]Permutations
查看>>
开始学习iOS开发
查看>>
从int 3探索Windows应用程序调试原理
查看>>
Java传参都是传引用变量的副本
查看>>
LINUX 内核结构
查看>>
Hexo+Github博客最简教程-Dockerfile自动搭建
查看>>
自学python记录_(3)函数
查看>>
ssh整合 class not found
查看>>
Linux(2)_常用命令2
查看>>
自定义分页
查看>>
[转]DELPHI——调试(1)
查看>>
JS秒数转成分秒时间格式
查看>>
xp_cmdshell 命令的开启与关闭,和状态查询
查看>>
Windows10下手工强制清理删掉安装版的JRE8导致java.exe无法运行的解决办法
查看>>
Linux sudoers
查看>>
MySQL详解(18)-----------分页方法总结
查看>>