gpt4 book ai didi

c# - 是否有与 Python 的 unhexlify 等效的 C#?

转载 作者:太空狗 更新时间:2023-10-30 02:50:39 26 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How to convert hex to a byte array?

我正在 C# 中寻找一个 python 兼容的方法来将十六进制转换为二进制。我通过这样做在 Python 中反转了哈希:

import sha
import base64
import binascii

hexvalue = "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8"
binaryval = binascii.unhexlify(hexvalue)
print base64.standard_b64encode(binaryval)
>> W6ph5Mm5Pz8GgiULbPgzG37mj9g=

到目前为止,我发现的所有各种 Hex2Binary C# 方法最终都会抛出 OverflowExceptions:

static string Hex2Binary(string hexvalue)
{
string binaryval = "";
long b = Convert.ToInt64(hexvalue, 16);
binaryval = Convert.ToString(b);
byte[] bytes = Encoding.UTF8.GetBytes(binaryval);
return Convert.ToBase64String(bytes);
}

有人知道如何生成 C# 方法来匹配 python 输出吗?

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