• MD5和SHA加密测试


    有关MD5和SHA加密,程序在SharpDevelop环境下测试。注意XP只支持MD5和SHA1,其他的不受XP系统支持。


    using System;
    using System.Net.NetworkInformation;

    namespace DemoConsole
    {
        class Program
        {
            public static void Main(string[] args)
            {   
                byte[] bytes = System.Text.Encoding.UTF8.GetBytes("XU Minghui");
                System.Security.Cryptography.MD5CryptoServiceProvider //MD5加密,16字节,128位
                    md5 =new System.Security.Cryptography.MD5CryptoServiceProvider();
                Console.WriteLine(BitConverter.ToString( md5.ComputeHash(bytes)).Replace("-",string.Empty));
                //TODO:SHA加密:20字节160位;32字节256位;48字节384位;64字节512位
                System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
                System.Security.Cryptography.SHA256CryptoServiceProvider sha256 = new System.Security.Cryptography.SHA256CryptoServiceProvider();
                System.Security.Cryptography.SHA384CryptoServiceProvider sha384 = new System.Security.Cryptography.SHA384CryptoServiceProvider();
                System.Security.Cryptography.SHA512CryptoServiceProvider sha512 = new System.Security.Cryptography.SHA512CryptoServiceProvider();
                
                Console.WriteLine("{0}\n{1}\n{2}\n{3}\n",
                                  BitConverter.ToString(sha1.ComputeHash(bytes)).Replace("-",string.Empty),
                                  BitConverter.ToString(sha256.ComputeHash(bytes)).Replace("-",string.Empty),
                                  BitConverter.ToString(sha384.ComputeHash(bytes)).Replace("-",string.Empty),
                                  BitConverter.ToString(sha512.ComputeHash(bytes)).Replace("-",string.Empty));
                
                Console.Write("Press any key to continue . . . ");
                Console.ReadKey(true);
            }
        }
    }

  • 相关阅读:
    SQL Server之4:游标原理和使用方法
    .Net MVC3之2:前台异步获取json数据的实例(2)
    通过url读取页面内容
    SharePoint 在页面查看错误信息
    添加列表时修改Title字段报错
    滚动新闻
    视频列表
    自定义列表部署
    SharePoint 2010 使用”日历重叠“功能(转)
    沙盒解决方案与场解决方案之间的差异(转)
  • 原文地址:https://www.cnblogs.com/flaaash/p/2022713.html
Copyright © 2020-2023  润新知