Skip to content

Commit 6e93212

Browse files
authored
Create pbkdf2hash.cs
1 parent 2ad686d commit 6e93212

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Encryption App/AES/pbkdf2hash.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Security.Cryptography;
3+
4+
namespace PBKDF2Hash
5+
{
6+
private static byte[] GenerateSalt()
7+
{
8+
var csprng = new RNGCryptoServiceProvider();
9+
var salt = new byte[32];
10+
csprng.GetBytes(salt);
11+
return salt;
12+
}
13+
14+
public static (byte[] hash, byte[] salt) pbkdf2hash(string password)
15+
{
16+
17+
string password = "passwd";
18+
byte[] salt = GenerateSalt();//warning shouldnt be random salts - change when you try and decrypt no?
19+
int iterations = 100000;
20+
byte[] hashValue;
21+
using (var pbkdf2 = new Rfc2898DeriveBytes(password, salt, iterations))
22+
{
23+
hashValue = pbkdf2.GetBytes(32);
24+
}
25+
return (hashValue,salt);
26+
}
27+
}

0 commit comments

Comments
 (0)