-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
65 lines (62 loc) · 1.88 KB
/
Copy pathProgram.cs
File metadata and controls
65 lines (62 loc) · 1.88 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Input;
namespace hash
{
class Program
{
static void Main()
{
while (true)
{
Console.WriteLine("Digite a string para realizar o calculo de hash:");
string sText = Console.ReadLine();
Console.WriteLine("MD5: " + GetMD5(sText));
Console.WriteLine("SHA256: " + GetSHA256(sText));
Console.WriteLine("SHA512: " + GetSHA512(sText));
Console.WriteLine("SHA1: " + GetSHA1(sText));
Console.WriteLine("");
Console.WriteLine("");
}
}
static string GetMD5(string input)
{
using (MD5 hash = MD5.Create())
{
return GetHash(hash, input);
}
}
static string GetSHA256(string input)
{
using (SHA256 hash = SHA256.Create())
{
return GetHash(hash, input);
}
}
static string GetSHA512(string input)
{
using (SHA512 hash = SHA512.Create())
{
return GetHash(hash, input);
}
}
static string GetSHA1(string input)
{
using (SHA1 hash = SHA1.Create())
{
return GetHash(hash, input);
}
}
static string GetHash(HashAlgorithm hash, string input)
{
byte[] data = hash.ComputeHash(Encoding.UTF8.GetBytes(input));
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
return sBuilder.ToString();
}
}
}