-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHash.cs
More file actions
executable file
·28 lines (25 loc) · 778 Bytes
/
Hash.cs
File metadata and controls
executable file
·28 lines (25 loc) · 778 Bytes
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
using System;
using System.Text;
using System.Security.Cryptography;
public class Hash
{
public static string coder(string input)
{
// Referência: https://gist.github.com/kristopherjohnson/3021045
// Converte string em array de bytes
byte[] bytes = Encoding.UTF8.GetBytes(input);
var sha1 = SHA1.Create();
byte[] hashBytes = sha1.ComputeHash(bytes);
return HexStringFromBytes(hashBytes);
}
public static string HexStringFromBytes(byte[] bytes)
{
var sb = new StringBuilder();
foreach (byte b in bytes)
{
var hex = b.ToString("x2");
sb.Append(hex);
}
return sb.ToString();
}
}