我正在研究加密MD5,我在谷歌找到了这个代码
public string CalculateMD5Hash(string input)
{
// Primeiro passo, calcular o MD5 hash a partir da string
MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
byte[] hash = md5.ComputeHash(inputBytes);
// Segundo passo, converter o array de bytes em uma string haxadecimal
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("X2"));
}
return sb.ToString();
}
Run Code Online (Sandbox Code Playgroud)
但为什么它使用ToString("X2")?ToString正常有什么区别?
在复杂性和安全性方面,哪种是最佳的整体哈希算法?md5还是sha1?
据我所知,md5比sha1快,但SHA1比md5更复杂.
我错过了什么吗?
我在Google上搜索过,我找不到使用Cryptsharp库的Scrypt用法代码示例(用于哈希密码).
你能提供哈希密码的样本吗?
什么是使用AES加密URL链接以使用VB.NET 2005将用户名传递到ASP.NET中的另一个网站的好链接或文章?仅供参考:接收网站将有权访问私钥以进行解密.
引用的代码来自这个答案,但类似的代码几乎无处不在。假设我们需要使用System.Security.Cryptography.HashAlgorithm.ComputeHash()接受byte[]. 典型的代码是这样的:
public static byte[] GetHash(string inputString)
{
HashAlgorithm algorithm = MD5.Create(); // SHA1.Create()
return algorithm.ComputeHash(Encoding.UTF8.GetBytes(inputString));
}
Run Code Online (Sandbox Code Playgroud)
字符串在内部存储为 Unicode。
为什么Encoding.UTF8用 代替Encoding.Unicode?