init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
45
Framework/Security/PasswordCrypting/BasePasswordCrypter.cs
Normal file
45
Framework/Security/PasswordCrypting/BasePasswordCrypter.cs
Normal file
|
@ -0,0 +1,45 @@
|
|||
using System;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Kreta.Framework.Security.PasswordCrypting
|
||||
{
|
||||
public static class BasePasswordCrypter
|
||||
{
|
||||
public static string EncodePasswordSHA1(string plainPassword, string salt)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(salt))
|
||||
{
|
||||
return plainPassword;
|
||||
}
|
||||
|
||||
string saltedPlainPassword = plainPassword + salt;
|
||||
using (HashAlgorithm hash = SHA1.Create())
|
||||
{
|
||||
byte[] passwordarray = Encoding.Unicode.GetBytes(saltedPlainPassword);
|
||||
byte[] hasharray = hash.ComputeHash(passwordarray);
|
||||
|
||||
string encryptedPassword = Convert.ToBase64String(hasharray);
|
||||
|
||||
return encryptedPassword;
|
||||
}
|
||||
}
|
||||
|
||||
public static string EncodePasswordMD5(string plainPassword)
|
||||
{
|
||||
using (HashAlgorithm hash = MD5.Create())
|
||||
{
|
||||
byte[] passwordArray = hash.ComputeHash(Encoding.UTF8.GetBytes(plainPassword));
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
foreach (byte item in passwordArray)
|
||||
{
|
||||
stringBuilder.Append(item.ToString("x2"));
|
||||
}
|
||||
var result = stringBuilder.ToString();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue