简体   繁体   English

PHP在解密之前将C#Hex Blob十六进制字符串转换回字节数组

[英]PHP Convert C# Hex Blob Hexadecimal String back to Byte Array prior to decryption

I have a piece of data that I am receiving in hexadecimal string format, example: "65E0C8DEB69EA114567954". 我有一个以十六进制字符串格式接收的数据,例如:“65E0C8DEB69EA114567954”。 It was made this way in C# by converting a byte array to a hexadecimal string. 它是通过将字节数组转换为十六进制字符串在C#中实现的。 However, I am using PHP to read this string and need to temporarily convert this back to the byte array. 但是,我使用PHP来读取此字符串,需要暂时将其转换回字节数组。 If it matters, I will be decrypting this byte array, then reconverting it to unencrypted hexadecimal and or plaintext, but I will figure that out later. 如果重要的话,我将解密这个字节数组,然后将其重新转换为未加密的十六进制和/或纯文本,但我稍后会想到这一点。

So the question is, how do I convert a string like the above back to an encoded byte array/ blob in PHP? 所以问题是,如何将上面的字符串转换回PHP中的编码字节数组/ blob

Thanks! 谢谢!

This does the trick: 这样做的诀窍:

$validHex = '65E0C8DEB69EA114567954';
$binStr = join('', array_map('chr', array_map('hexdec', str_split($validHex, 2))));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM