Thứ sáu, ngày 02 tháng bảy năm 2010

Encrypt - Decrypt SHA

- Mã hóa dịch ngược

public class EncryptePass
{
public EncryptePass()
{

}
public static string Encrypt(string inputString)
{
if (inputString == null || inputString.Length == 0) return string.Empty;
string result = string.Empty;
try
{
byte[] buffer = Encoding.UTF8.GetBytes(inputString);
SHA512 SHAHash = new SHA512Managed();
result = Convert.ToBase64String(SHAHash.TransformFinalBlock(buffer, 0, buffer.Length));
}
catch
{
throw;
}
return result;
}

public static string Decrypt(string inputString)
{
if (inputString == null || inputString.Length == 0) return string.Empty;
string result = string.Empty;
try
{
byte[] buffer = Convert.FromBase64String(inputString);
SHA512 SHAHash = new SHA512Managed();
result = Encoding.UTF8.GetString(SHAHash.TransformFinalBlock(buffer, 0, buffer.Length));
}
catch
{
throw;
}
return result;
}
}

- Mã hóa không dịch ngược

public static string Encrypt(string inputString)
{
if (inputString == null || inputString.Length == 0) return string.Empty;

string result = string.Empty;

try
{
byte[] buffer = Encoding.UTF8.GetBytes(inputString);
SHA512 SHAHash = new SHA512Managed();
result = Convert.ToBase64String(SHAHash.ComputeHash(buffer, 0, buffer.Length));
}
catch
{
throw;
}
return result;
}


Mọi chi tiết xin liên hệ: duyhung109@Gmail.com