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!

TheFrack
  • 2,823
  • 7
  • 28
  • 47

1 Answers1

2

This does the trick:

$validHex = '65E0C8DEB69EA114567954';
$binStr = join('', array_map('chr', array_map('hexdec', str_split($validHex, 2))));
Ron
  • 1,336
  • 12
  • 20
  • 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. – TheFrack Jul 06 '12 at 12:23
  • 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: http://www.codeproject.com/Articles/16822/The-Anatomy-of-Forms-Authentication Thanks again! – TheFrack Jul 06 '12 at 12:41
  • http://stackoverflow.com/questions/578679/is-forms-authentication-ticket-decryption-possible-with-php – Ron Jul 06 '12 at 12:54
  • 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. – TheFrack Jul 06 '12 at 13:14