代码1:(将SHA1结果转换为字符串的简单方法)
byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
SHA1CryptoServicesProvider x = new SHA1CryptoServicesProvider();
bs = x.ComputeHash(bs);
System.Text.StringBuilder s = new System.Text.StringBuilder();
foreach (byte b in bs)
s.Append(b.ToString("x2").ToLower());
result1 = s.ToString();
Code2:(从世界之初就存在于项目中的遗留代码)
byte[] bs = System.Text.ASCIIEncoding.GetBytes(input);
SHA1CryptoServicesProvider x = new SHA1CryptoServicesProvider();
bs = x.ComputeHash(bs);
char[] c = new char[bs.length]
for(int i=0; i<bs.length; i++)
c[i] = (char)(bs[i] & 0x7f);
resutl2 = new StringBuilder().Append(c).ToString();
有什么map()
函数可以用来评估result1
吗result2
?
result1 == map(result2)
“代码 2”是什么意思0x7f
?