Reputation: 2873
I have a piece of data that I am receiving in hexadecimal string format, example: "65E0C8DEB69EA114567954". It was made this way in C# by converting a byte array to a hexadecimal string. However, I am using PHP to read this string and need to temporarily convert this back to the byte array. 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?
Thanks!
Upvotes: 0
Views: 1349
Reputation: 1336
This does the trick:
$validHex = '65E0C8DEB69EA114567954';
$binStr = join('', array_map('chr', array_map('hexdec', str_split($validHex, 2))));
Upvotes: 2