c# - 在 Windows Phone 8.1 上找不到类型 System.Security.Cryptography.SHA256

标签 c# encryption windows-phone-8.1 windows-8.1 sha

我想在 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

然后计算哈希值。

然后,如果您愿意,可以将其编码为十六进制字符串。


我的哈希应用程序的无耻截图:)

Click Here for Fullsize Image enter image description here

关于c# - 在 Windows Phone 8.1 上找不到类型 System.Security.Cryptography.SHA256,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26969469/

相关文章:

c#程序sql语法错误

c# - 在开源应用程序中存储已保存的密码

javascript - IE11(Windows Phone 8.1)无法感应(显示尺寸)屏幕旋转?

c# - EF4 代码优先 CTP5 多对一

c# - 将 ORACLE SDO_GEOMETRY 导入 SQL Server 几何

c# - Webmatrix - 将变量从 cshtml 页面传递到 aspx 页面

java - 使用java代码生成的公钥的格式

python - 遇到 : json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

c# - Frame.Navigate 到不同程序集中的 Page 派生类

c# - BackgroundMediaPlayer.MessageReceivedFromBackground 不工作