nove verzije
This commit is contained in:
@@ -102,5 +102,32 @@ namespace ResevalnaScanner.Classes
|
||||
|
||||
return Encoding.UTF8.GetString(plainTextBytes, 0, byteCount).Trim();
|
||||
}
|
||||
|
||||
public const int SALT_SIZE = 24; // size in bytes
|
||||
public const int HASH_SIZE = 256; // size in bytes
|
||||
public const int ITERATIONS = 20000; // number of pbkdf2 iterations
|
||||
|
||||
public static (byte[] Hash, byte[] Salt) CreatePasswordHash(string iText, byte[]? iSalt = null)
|
||||
{
|
||||
byte[] salt;
|
||||
if (iSalt == null)
|
||||
{
|
||||
salt = new byte[SALT_SIZE];
|
||||
using var rng = RandomNumberGenerator.Create();
|
||||
rng.GetBytes(salt);
|
||||
}
|
||||
else
|
||||
{
|
||||
salt = iSalt;
|
||||
}
|
||||
|
||||
var pbkdf2 = new Rfc2898DeriveBytes(iText, salt, ITERATIONS, HashAlgorithmName.SHA256);
|
||||
return (pbkdf2.GetBytes(HASH_SIZE), salt);
|
||||
}
|
||||
|
||||
public static bool CompareByteArrays(byte[] iArray, byte[] iArrayToCompare)
|
||||
{
|
||||
return iArray.Length == iArrayToCompare.Length && !iArray.Where((t, i) => t != iArrayToCompare[i]).ToList().Any();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user