2018-11-28 15:43:30 +01:00
|
|
|
|
/*
|
2024-03-05 18:13:14 +01:00
|
|
|
|
* Copyright (c) 2023 ETH Zürich, IT Services
|
2018-11-28 15:43:30 +01:00
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
using System.Text;
|
2019-08-30 09:55:26 +02:00
|
|
|
|
using SafeExamBrowser.Configuration.Contracts.Cryptography;
|
2018-11-28 15:43:30 +01:00
|
|
|
|
|
2018-12-14 09:50:10 +01:00
|
|
|
|
namespace SafeExamBrowser.Configuration.Cryptography
|
2018-11-28 15:43:30 +01:00
|
|
|
|
{
|
|
|
|
|
public class HashAlgorithm : IHashAlgorithm
|
|
|
|
|
{
|
|
|
|
|
public string GenerateHashFor(string password)
|
|
|
|
|
{
|
|
|
|
|
using (var algorithm = new SHA256Managed())
|
|
|
|
|
{
|
|
|
|
|
var bytes = Encoding.UTF8.GetBytes(password);
|
|
|
|
|
var hash = algorithm.ComputeHash(bytes);
|
|
|
|
|
var hashString = String.Join(String.Empty, hash.Select(b => b.ToString("x2")));
|
|
|
|
|
|
|
|
|
|
return hashString;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|