0

I need to convert a PDF encoded as HEX, back into a base 64 string via JavaScript. I only have access to the hex string, not to the encoding tools, so I can't reverse engineer it. From what I've been told and can 'see' when I convert the hex to base64, the document is encoded with Aspose.Words for .NET.

See converted hex into string (converted to string to see if I could find anything useful):

converted hex into string

I'm kind of at a loss here. I've tried encoding and decoding to many different formats, but the above picture is the best I've done. Is the document maybe encrypted?

Thanks

EDIT:

I've since posting tried different things. Got them to send me a couple of files retrieved decoded as XML PATH (seems to be base64), but when I try and open the file (its recognised as b64), the file is corrupted.

Converting the file from hex -> base64 -> file doesn't work (using base64.guru for testing). The file is recognised as b64, but can't load.

Carl-Johan
  • 77
  • 4
  • 11
  • could you please share the source hex string here? As I can see from the screenshot it is a simple PDF document. So theoretically, if your destination s base64 string, you should convert hex string to byte array and then encode byte array as base64 string. – Alexey Noskov Oct 05 '21 at 11:38
  • Thanks for the reply @AlexeyNoskov. Unfortunately I cannot post the source HEX as it contains sensitive information. I just used the online tool https://cryptii.com/pipes/base64-to-hex, where I took the initial hex, got it's hexadecimal value (pairs of two) and then encoded that as base64. Decoding the base 64 ofcourse just returned the hex. I'm surely misunderstanding something here. – Carl-Johan Oct 05 '21 at 12:08
  • The hex has the following format : 0x255044462D312E370D0A342030206F626A0D0A3C3C2F54797065202F506167652F506172656E742033203020522F436F6E74656E74732035203020522F4D65646961426F78205B302030203539352E3239393938373739203834312E39303030323434315D2F5265736F75726365733C3C2F466F6E743C3C2F4641414141482037203020522F464141414241203130203020522F464141414243203132203020522F464141414246203135203020523E3E2F58 (and so fourth) – Carl-Johan Oct 05 '21 at 12:19
  • My goal is to render the original HEX as a pdf. @AlexeyNoskov – Carl-Johan Oct 06 '21 at 07:37
  • I've since posting tried different things. Got them to send me a couple of files retrieved decoded as XML PATH (seems to be base64), but when I try and open the file (its recognised as b64), the file is corrupted. – Carl-Johan Oct 11 '21 at 07:39

1 Answers1

0

I still dont see why there should still be a problem unless the file is truly corrupted.

First convert the HEX TEXT to a PDF

here is one example using http://tomeko.net/online_tools/hex_to_file.php?lang=en

enter image description here

If you open/save the Hex in an editor (that means everything after the 0x) you should instantly have your A4.PDF, so save it as such and check it is readable in a pdf viewer.

enter image description here

If it does not view as an A4 page or more (you need to give us at least 3 0 obj to potentially see how many pages are included) then the hex is no good

You say you then take the HEX and convert to Base64 ![enter image description here

Thus if the HEX is fully VALID to reprex (REPRoducable EXample) a Binary.pdf so too should be the translated JVBER.base64

if the hex (without any 0x) does not translate into a viewable binary file, 1st check it looks like the start is %PDF-#.# as shown, where numbers are version and ideally second line should also start % followed by 4 hieroglyphic characters which are not shown above, but should be the case for most binary pdfs. then it "should" be viewable in PDF preview etc. If it does not view except say as a blank page then there was corruption before or after the hex was produced and may possibly need a full or partial recovery by fixing the trailer.

K J
  • 8,045
  • 3
  • 14
  • 36
  • Thanks for the detailed explanation (I know how to deal with b64, but i'm not expert in encoding/decoding). I just did everything you asked (also did many times before). Converting the hex (after 0x) to b64, saving the b64 as a file (with and without ```data:application/pdf;base64,```) to no avail. Acrobat Reader or Mac's standard Preview don't want to open the file. I have reached out to the supplier for additional information. – Carl-Johan Oct 15 '21 at 07:11
  • hm. Google hasn't been able to teach me what *reprex* means and how it works, so apologies for sounding ignorant: what is reprex? can I convert it (?) programatically? how do I get a pdf viewer to translate it (save the hex as file?). I sure am learning a lot ... :) – Carl-Johan Oct 15 '21 at 10:15
  • So if I paste my hex into the link you supplied and the created pdf is still not able to be opened - is the hex then no good or am I completely lost ? :/ – Carl-Johan Oct 15 '21 at 13:47
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/238166/discussion-between-carl-johan-beurling-and-k-j). – Carl-Johan Oct 15 '21 at 14:24