This commit is contained in:
skidoodle 2024-03-13 00:33:46 +01:00
commit e124a47765
19374 changed files with 9806149 additions and 0 deletions

View file

@ -0,0 +1,28 @@
using System.Security.Cryptography;
namespace Kreta.Framework
{
/// <summary>
/// Só generálására használatos segédosztály
/// </summary>
public static class SaltGenerator
{
/// <summary>
/// Generál egy véletlen sót.
/// </summary>
/// <remarks>
/// A só generálása <see cref="System.Security.Cryptography.RandomNumberGenerator"/> segítségével történik.
/// </remarks>
/// <returns>Véletlen só karakterláncként, ami csak számjegyekből áll</returns>
public static string GenerateSalt()
{
RandomNumberGenerator generator = RNGCryptoServiceProvider.Create();
byte[] randombytes = new byte[8];
generator.GetNonZeroBytes(randombytes);
ulong salt =
((ulong)randombytes[7] << 56) + ((ulong)randombytes[6] << 48) + ((ulong)randombytes[5] << 40) + ((ulong)randombytes[4] << 32) +
((ulong)randombytes[3] << 24) + ((ulong)randombytes[2] << 16) + ((ulong)randombytes[1] << 8) + (ulong)randombytes[0];
return salt.ToString();
}
}
}