36 lines
935 B
C#
36 lines
935 B
C#
using Isopoh.Cryptography.Argon2;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Akari.Prototype.Server.Utils
|
|
{
|
|
public static class Security
|
|
{
|
|
public const int HashLength = 32;
|
|
public const int SaltLength = 12;
|
|
|
|
public static string Argon2idHash(byte[] password)
|
|
{
|
|
var salt = new byte[8];
|
|
|
|
RandomNumberGenerator.Fill(salt);
|
|
|
|
var config = new Argon2Config()
|
|
{
|
|
HashLength = 32,
|
|
Lanes = Environment.ProcessorCount / 2,
|
|
Threads = Environment.ProcessorCount / 2,
|
|
Password = password,
|
|
Salt = salt,
|
|
Type = Argon2Type.HybridAddressing,
|
|
Version = Argon2Version.Nineteen
|
|
};
|
|
|
|
return Argon2.Hash(config);
|
|
}
|
|
}
|
|
}
|