two commonly used encryption methods in C #:
Personal mark, for reference only.
Public static class Extends
{
/// <summary>
/// HMAC SHA256
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
Public static string Sha256(this string str)
{
Byte[] sha256Data = Encoding.UTF8.GetBytes(str);
SHA256Managed sha256 = new SHA256Managed();
Byte[] buffer = sha256.ComputeHash(sha256Data);
// You can process the encrypted byte array as needed, for example using Base64. Use BitConverter to convert to 64 characters.
Return BitConverter.ToString(buffer).Replace("-", "").ToLower();
}
/// <summary>
/// MD5
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
Public static string Md5(this string str)
{
Var md5 = MD5.Create();// Encrypted is an array of byte types
Byte[] buffer = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
// The resulting string is in hexadecimal type format. The characters after the format are lowercase letters. If uppercase (X) is used, the characters after the format are uppercase characters.
Return buffer.Aggregate(string.Empty, (current, t) => current + t.ToString("x"));
}
}
Hmac-sha256 & MD5 in C #