1
This commit is contained in:
20
Assets/BITKit/Core/Crypto/Core/BITCrypto.cs
Normal file
20
Assets/BITKit/Core/Crypto/Core/BITCrypto.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Security.Cryptography;
|
||||
namespace BITKit.Crypto
|
||||
{
|
||||
public class BITCrypto:ICryptography
|
||||
{
|
||||
public string Salt { get; set; } = "2196F3";
|
||||
public string Hash(string password)
|
||||
{
|
||||
var data = System.Text.Encoding.UTF8.GetBytes(password + Salt);
|
||||
return Convert.ToBase64String(data);
|
||||
}
|
||||
|
||||
public bool Verify(string password, string hash)
|
||||
{
|
||||
return Hash(password) == hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
26
Assets/BITKit/Core/Crypto/Core/ICryptography.cs
Normal file
26
Assets/BITKit/Core/Crypto/Core/ICryptography.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
namespace BITKit.Crypto
|
||||
{
|
||||
/// <summary>
|
||||
/// 加密接口
|
||||
/// </summary>
|
||||
public interface ICryptography
|
||||
{
|
||||
/// <summary>
|
||||
/// 盐
|
||||
/// </summary>
|
||||
public string Salt { get; set; }
|
||||
/// <summary>
|
||||
/// 获取Hash
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public string Hash(string password);
|
||||
/// <summary>
|
||||
/// 验证密码是否有效
|
||||
/// </summary>
|
||||
/// <param name="password">明文密码</param>
|
||||
/// <param name="hash"></param>
|
||||
/// <returns></returns>
|
||||
public bool Verify(string password, string hash);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user