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

    环境:vs.net2005/sql server2000/xp测试通过
      1.MD5 16位加密实例
       using System;
      using System.Collections.Generic;
      using System.Text; 
      using System.Security.Cryptography;
      
      namespace md5
      {
       class Program
       {
       static void Main(string[] args)
       {
       Console.WriteLine(UserMd5("8"));
       Console.WriteLine(GetMd5Str("8"));
       }
       /**//// <summary>
       /// MD5 16位加密
       /// </summary>
       /// <param name="ConvertString"></param>
       /// <returns></returns>
       public static string GetMd5Str(string ConvertString)
       {
       MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
       string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8);
       t2 = t2.Replace("-", "");
       return t2;
       }
      http://www.cnblogs.com/sopper/archive/2007/01/08/615111.html
       /**//// <summary>
       /// MD5 32位加密
       /// </summary>
       /// <param name="str"></param>
       /// <returns></returns>
       static string UserMd5(string str)
       {
       string cl = str;
       string pwd = "";
       MD5 md5 = MD5.Create();//实例化一个md5对像
       // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择 
       byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
       // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
       for (int i = 0; i < s.Length; i++)
       {
       // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
      
       pwd = pwd + s[i].ToString("X");
      
       }
       return pwd;
       }
       }
      } 
  • 相关阅读:
    CentOS常用的文件操作命令总结
    消息队列技术
    net license tool, EasyLicense !
    Socket、Session、Option和Pipe
    安全配置基线Linux系统
    SolrCloud
    线性表
    微服务系统中的认证策略
    How to use JDBC-Authentication of Spring Boot/Spring Security with Flyway
    使用Akka、Kafka和ElasticSearch等构建分析引擎 -- good
  • 原文地址:https://www.cnblogs.com/niuniu502/p/929487.html
Copyright © 2011-2022 走看看