1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.Security;
5
using System.Security.Cryptography;
6
namespace 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
}
using System;2
using System.Collections.Generic;3
using System.Text;4
using System.Security;5
using System.Security.Cryptography;6
namespace ConsoleApplication37
{8
class Program9
{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,最后长度就不一了


浙公网安备 33010602011771号