引用System.Security.Cryptography、System.Text名稱空間
使用SHA256加密字串:
public string GetSHA256(string input)
{
SHA256 sha256 = new SHA256CryptoServiceProvider();
byte[] source = Encoding.Default.GetBytes(input);
byte[] crypto = sha256.ComputeHash(source);
string result = Convert.ToBase64String(crypto);
return result;
}
使用SHA384加密字串:
public string GetSHA384(string input)
{
SHA384 sha384 = new SHA384CryptoServiceProvider();
byte[] source = Encoding.Default.GetBytes(input);
byte[] crypto = sha384.ComputeHash(source);
string result = Convert.ToBase64String(crypto);
return result;
}
使用SHA512加密字串:
public string GetSHA512(string input)
{
SHA512 sha512 = new SHA512CryptoServiceProvider();
byte[] source = Encoding.Default.GetBytes(input);
byte[] crypto = sha512.ComputeHash(source);
string result = Convert.ToBase64String(crypto);
return result;
}
沒有留言:
張貼留言