1using System;
 2using System.Collections.Generic;
 3using System.Text;
 4using System.Security;
 5using System.Security.Cryptography;
 6namespace ConsoleApplication3
 7{
 8    class Program
 9    {
10        static void Main(string[] args)
11        {
12            string a = Console.ReadLine();
13            SHA1 sha=new SHA1CryptoServiceProvider();
14            UTF8Encoding utf = new UTF8Encoding();
15            byte[] s1 = utf.GetBytes(a);
16            byte[] s2 = sha.ComputeHash(s1);
17            sha.Clear();
18            for (int i = 0; i < s2.Length;i++ )
19            {
20                Console.Write("\t"+Convert.ToString(s2[i], 16).PadLeft(2,'0')+" "+s2[i]);
21                
22            }

23            Console.Read();
24        }

25       
26       
27    }

28
29}

今天正好碰到,由于C\S和B\S共用,产生了一些无聊的问题,B\S用SHA1加密时字符串长度在40,保持不变,可是C\S用SHA1加密时字符串长度会出现小于40。
由于Byte进行散列时,会有出现0,再进行convert转换时,原本是00的,就变成了0,最后长度就不一了
posted on 2007-07-22 11:58  年轻活力  阅读(547)  评论(0编辑  收藏  举报