예제 #1
0
파일: Crypto.cs 프로젝트: Mempler/Sora
            public static (string password, byte[] salt) generate_hash(string password, int rounds = 20)
            {
                var pwBytes     = Hex.IsHex(password) ? Hex.FromHex(password) : Encoding.Default.GetBytes(password);
                var saltBytes   = generate_salt();
                var pwHashBytes = scr.Generate(pwBytes, saltBytes, 262144 / 4, rounds, 1, 512);

                return(Convert.ToBase64String(pwHashBytes), saltBytes);
            }
예제 #2
0
파일: Crypto.cs 프로젝트: Mempler/Sora
            public static bool validate_password(string password, string hash, byte[] salt, int rounds = 20)
            {
                var pwBytes     = Hex.IsHex(password) ? Hex.FromHex(password) : Encoding.Default.GetBytes(password);
                var pwHashBytes = scr.Generate(pwBytes, salt, 262144 / 4, rounds, 1, 512);
                var hashBytes   = Convert.FromBase64String(hash);


                return(pwHashBytes.SequenceEqual(hashBytes));
            }