-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHMAC.cs
45 lines (37 loc) · 1.14 KB
/
HMAC.cs
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
using System;
using System.Security.Cryptography;
namespace Crypto
{
public class HMAC
{
private static int keySize=32;
public static byte[] GenerateKey(){
using(var randomNumberGenerator= new RNGCryptoServiceProvider()){
var randomNumber=new byte[keySize];
randomNumberGenerator.GetBytes(randomNumber);
return randomNumber;
}
}
public static byte[] ComputeHmacSah256(byte[] toBeHashed, byte[] key)
{
using (var hmacSah256 = new HMACSHA256(key))
{
return hmacSah256.ComputeHash(toBeHashed);
}
}
public static byte[] ComputeHmacSah512(byte[] toBeHashed, byte[] key)
{
using (var hmacSah256 = new HMACSHA512(key))
{
return hmacSah256.ComputeHash(toBeHashed);
}
}
public static byte[] ComputeHmacMD5(byte[] toBeHashed, byte[] key)
{
using (var hmacMd5= new HMACMD5(key))
{
return hmacMd5.ComputeHash(toBeHashed);
}
}
}
}