-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHash.cs
29 lines (26 loc) · 933 Bytes
/
Hash.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
using System;
using System.Security.Cryptography;
namespace Crypto{
class Hash
{
public static byte[] GenerateSalt(){
const int saltLength=32;
using(var randomNumberGenerator= new RNGCryptoServiceProvider()){
var random= new byte[saltLength];
randomNumberGenerator.GetBytes(random);
return random;
}
}
public static byte[] Combine(byte[] first, byte[] second){
var ret= new byte[first.Length+second.Length];
Buffer.BlockCopy(first,0,ret,0,first.Length);
Buffer.BlockCopy(second,0,ret,first.Length,second.Length);
return ret;
}
public static byte[] HashPasswordWithSalt(byte[] toBeHashed, byte[] salt){
using(var sha256= SHA256.Create()){
return sha256.ComputeHash(Combine(toBeHashed,salt));
}
}
}
}