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

    下面试运算结果

  • 相关阅读:
    Centos6.5安装Oracle11.2.0.4 RAC(完整版)
    VMware搭建Oracle 11g RAC测试环境 For Linux
    Linux CentOS命令行界面字体重复问题解决记录
    SSH公钥认证(码云)
    Git 上传本地仓库到码云
    Git 相关工具及教程地址
    jdk8 新特性stream().map()
    PowerDesigner 使用记录
    IDEA 中.properties文件中文自动转Unicode编码及乱码问题
    idea在Maven Projects中显示灰色的解决办法
  • 原文地址:https://www.cnblogs.com/gouguo/p/2707433.html
Copyright © 2011-2022 走看看