Windows Phone 中的 SHA-1 算法

本文关键字:算法 SHA-1 中的 Phone Windows | 更新日期: 2023-09-27 18:36:58

在我的Windows Phone应用程序中,我需要使用SHA-1算法获取哈希。我该怎么做?例如,我有string text="1234";

Windows Phone 中的 SHA-1 算法

您可以使用

SHA1Managed 类来计算字节数组的哈希。可能会做这样的事情:

var sha = new SHA1Managed(); 
var bytes = System.Text.Encoding.UTF8.GetBytes(text);
byte[] resultHash = sha.ComputeHash(bytes);
SHA1 sha = new SHA1CryptoServiceProvider(); 
byte[] result = sha.ComputeHash(System.Text.Encoding.UTF8.GetBytes(text));

您应该使用 System.Security.Cryptography.SHA1Managed 类。