use salt and password to create a key

This commit is contained in:
Tim Young 2017-08-01 08:52:16 -05:00
parent 7b731e22a4
commit 96a24d033b
1 changed files with 16 additions and 1 deletions

View File

@ -137,7 +137,7 @@ namespace EduNetworkBuilder
public static string GenSalt(Random RanGen)
{
return GenCharString(RanGen, 20);
return GenCharString(RanGen, 50);
}
public static string GenUserPW(Random RanGen)
@ -145,5 +145,20 @@ namespace EduNetworkBuilder
return GenCharString(RanGen, 6);
}
public static TripleDES GenKey(string password, string salt)
{
TripleDESCryptoServiceProvider tDESkey = new TripleDESCryptoServiceProvider();
byte[] saltBytes = Encoding.UTF8.GetBytes(salt);
var p = new Rfc2898DeriveBytes(password, saltBytes);
tDESkey.IV = p.GetBytes(tDESkey.BlockSize / 8);
tDESkey.Key = p.GetBytes(tDESkey.KeySize / 8);
return tDESkey;
}
public void SetKey(string password, string salt)
{
algValue = GenKey(password, salt);
}
}
}