28 lines
1.1 KiB
C#
28 lines
1.1 KiB
C#
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();
|
|
}
|
|
}
|
|
}
|