Possible en double:
How to convert hex to a byte array?Existe-t-il un C# équivalent à unhexlify de Python?
Je cherche une méthode python compatible en C# pour convertir hexadécimal en binaire. J'ai renversé un hachage en Python en faisant ceci:
import sha
import base64
import binascii
hexvalue = "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8"
binaryval = binascii.unhexlify(hexvalue)
print base64.standard_b64encode(binaryval)
>> W6ph5Mm5Pz8GgiULbPgzG37mj9g=
Jusqu'à présent, toutes les différentes Hex2Binary méthodes C# J'ai trouvé finissent par jeter 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);
}
Quelqu'un a une astuce sur la façon dont produire une méthode C# pour correspondre à la sortie de python?
en double de http://stackoverflow.com/questions/854012/how-to-convert-hex-to-a-byte-array –
(utilisation Convert.ToBase64String avec le résultat byte array, btw.) –
Ce n'est pas un IMO en double, c'est spécifique à la compatibilité entre Python et C#. La réponse peut être la même, mais la question (sur laquelle les autres peuvent tomber) est certainement différente. – RyanW