gpt4 book ai didi

c# - 在没有 System.Security.Cryptography 的情况下计算 SHA256 哈希

转载 作者:行者123 更新时间:2023-11-30 19:55:40 25 4
gpt4 key购买 nike

我正在将我的一个库移动到 Xamarin PLC。

官方文档指出支持 System.Security.Cryptography 命名空间,但在实际代码中并不支持。

我正在寻找一种在没有此命名空间的情况下计算 SHA256 哈希的方法(并且在 Windows 命名空间中没有 HashAlgorithmProvider。此方法会破坏 Android 和 WP8.0 的应用程序)

最佳答案

使用 Bouncy CaSTLe PCL 库 (https://www.nuget.org/packages/Portable.BouncyCastle/) 测试类似的东西

var encData = Encoding.UTF8.GetBytes("TESTHASH");
Org.BouncyCastle.Crypto.Digests.Sha256Digest myHash = new Org.BouncyCastle.Crypto.Digests.Sha256Digest();
myHash.BlockUpdate (encData, 0, encData.Length);
byte[] compArr = new byte[myHash.GetDigestSize ()];
myHash.DoFinal (compArr, 0);

关于c# - 在没有 System.Security.Cryptography 的情况下计算 SHA256 哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36464840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com