我想在 Windows Phone 8.1 c# xaml 上使用 SHA 256 加密。 但我收到以下错误: 在模块 mscorlib.dll 中找不到类型 System.Security.Cryptography.HashAlgorithm
事实上,System.Security.Cryptography 在 Windows Phone(或 Windows 8 商店)上不可用。 不过,Windows.Security.Cryptography 是可用的,但我也找不到此类。
使用 SHA 256 加密需要什么?有 dll 吗?
谢谢
最佳答案
如果你做的是通用应用程序,那就有点困难了。但为了让你开始
using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
HashAlgorithmProvider hap = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
CryptographicHash ch = hap.CreateHash();
// read in bytes from file then append with ch.Append(data)
Windows.Storage.Streams.IBuffer b_hash = ch.GetValueAndReset(); // hash it
string hash_string = CryptographicBuffer.EncodeToHexString(b_hash); // encode it to a hex string for easy reading
您必须创建一个 HashAlgorithmProvider 并向其提供您要使用的 HashAlgorithm
请参阅 HashAlgorithmNames.
命名空间以了解所有支持的哈希
然后根据上面的内容创建一个CryptographicHash
。
然后使用 .Append(data)
将字节添加到 CryptographicHash
中
然后计算哈希值。
然后,如果您愿意,可以将其编码为十六进制字符串。
我的哈希应用程序的无耻截图:)
关于c# - 在 Windows Phone 8.1 上找不到类型 System.Security.Cryptography.SHA256,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26969469/