由于this constructor类的BigInteger
,我有一个可与.netstandard2.1 / netcore3.0一起使用的代码。此ctor不适用于netstandard2.0,我希望能够在不强制使用netstandard2.1的情况下实现相同的功能。
这里是问题:
这是我的可与.netstandard2.1配合使用的解决方案
static SHA256 sha256 = SHA256.Create();
internal static string GetEncoded(string value)
{
var data = sha256.ComputeHash(value.GetUTF8Bytes());
return new BigInteger(
value: data,
isUnsigned: true,
isBigEndian: true).ToString();
}
这是netstandard2.0中的解决方案,很遗憾,它不会产生相同的结果。
internal static string GetEncoded(string value)
{
var data = sha256.ComputeHash(value.GetUTF8Bytes());
return new BigInteger(value: data).ToString();
}
这里有一些样本值及其预期的编码输出。
"encoded": "68086943237164982734333428280784300550565381723532936263016368251445461241953",
"raw": "101 Wilson Lane"
"encoded": "101327353979588246869873249766058188995681113722618593621043638294296500696424",
"raw": "SLC"
据我了解,BigInteger(byte[])
ctor期望一个小的字节序字节数组。我尝试的几种解决方案均未取得预期的结果,因此我将向SO寻求答案。任何帮助将不胜感激。
您可以对其进行修改,以便用字节[]代替ReadOnlySpan。