-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHash - SHA256.linq
53 lines (45 loc) · 1.03 KB
/
Hash - SHA256.linq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<Query Kind="Program">
<Reference><RuntimeDirectory>\System.Security.dll</Reference>
<Namespace>System.Security.Cryptography</Namespace>
</Query>
void Main()
{
byte[] bytes = Encoding.Unicode.GetBytes("abcd");
SHA256Managed hashstring = new SHA256Managed();
byte[] hash = hashstring.ComputeHash(bytes);
//hash.Dump(true);
Console.WriteLine(F(hash));
Alpha a = new Alpha()
{
id = 100,
name = "Omega 1",
updatedt = DateTime.Parse("01/10/2000"),
value = 333.7
};
using(MemoryStream ms = new MemoryStream())
using(BinaryWriter bw = new BinaryWriter(ms))
{
bw.Write(a.id);
bw.Write(a.name);
bw.Write(a.updatedt.ToBinary());
bw.Write(a.value);
hash = hashstring.ComputeHash(ms);
}
Console.WriteLine(F(hash));
}
string F(byte[] d)
{
StringBuilder rc = new StringBuilder();
foreach (byte x in d)
{
rc.AppendFormat("{0:x2}", x);
}
return rc.ToString();
}
class Alpha
{
public int id { get; set; }
public string name {get; set;}
public DateTime updatedt {get; set;}
public double value {get; set;}
}