zoukankan      html  css  js  c++  java
  • 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);
            }
        }
    }

  • 相关阅读:
    (Java随机数举例)随机扔一千次硬币的正反次数
    hibernate+spring的整合思路加实例(配图解)
    从零开始学C++之IO流类库(三):文件的读写、二进制文件的读写、文件随机读写
    ssh连接Linux自动断开后再也无法连上的问题
    面试题10:二进制中1的个数
    C 语言统计关键字出现次数
    在Eclipse中Attach Source
    Visual Sudio 2012转换界面风格
    java 判断字符串IP合法性以及获取IP的数值形式
    java.lang.string split 以点分割字符串无法正常拆分字符串
  • 原文地址:https://www.cnblogs.com/flaaash/p/2022713.html
Copyright © 2011-2022 走看看