nove verzije

This commit is contained in:
David Štaleker
2024-08-02 11:00:59 +02:00
parent edab522e0e
commit ca229fbd89
8 changed files with 491 additions and 157 deletions

View File

@@ -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();
}
}
}