0

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!

1 Answer 1

2

This does the trick:

$validHex = '65E0C8DEB69EA114567954';
$binStr = join('', array_map('chr', array_map('hexdec', str_split($validHex, 2))));
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you good sir, now I have to figure out how to decrypt it from that step or if I have to add another method.
Basically I'm trying to do this... Hex String => Byte Array => Decrypt Byte Array => Turn into Plaintext. I'm trying to get the data that the following article talks about: codeproject.com/Articles/16822/… Thanks again!
Yeah, basically I'm taking what you wrote, plugging it into various AES decryption methods using Rijndael 128, not sure if that is working, but now I'm trying to get it back as plain text to verify.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.