Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    How to extract base64 code out of a file?

    Dear members im having text file which contains 1 or 2 base64 blocks of code. Following is part of the file and 1 base64 block.

    Content-Transfer-Encoding: base64

    RGVhciBMdWlzLA0KICANCkdvb2QgbW9uaW5nIQ0KT3VyIEJhbm sgYWNjb3VudCBpcyB1bmRlcmdvaW5nIGF1ZGl0IGZvciB0aGUg ZmlzY2FsIHllYXIgYXMgcmVxdWlyZWQgYnkgdGhlIGNoaW5hIG ZvcmVpZ24gY3VycmVuY3kgY29udHJvbCBwb2xpY3kgYW5kIHRo ZSBhY2NvdW50IHdpbGwgbm90IGJlIGF2YWlsYWJsZSB1bnRpbC B0aGUgQ2hpbmVzZSB0YXggYnVyZWF1cyBhcmUgc
    2F0aXNmaWVkIHRoYXQgYWxsIGFwcGxpY2FibGUgdGF4ZXMgaGF 2ZSBiZWVuIHBhaWQgdXAuIFBsZWFzZSBob2xkIHBheW1lbnQgc 28gaSBjYW4gZnVybmlzaCB5b3Ugd2l0aCBvdXIgcmV2aXNlZCB iYW5raW5nIGluZm9ybWF0aW9uLiAgDQoNCiAgDQpCZXN0IHJlZ 2FyZHMNCiANCkRhdmlk

    Being on Linux, which command i can do to extract first base64 out of the file? My aim is to decode output to be readable


    Example file decode command: How can I extract an attachment from the email body (encoded as base64) - Super User
    Example phrasse decode command: bash - How can I decode a base64 string from the command line? - Ask Ubuntu

    but i do not know how to extract only the base64 phrasse out of file which also contains non base64 contents.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Whether or not it is decode-able into ascii format depends. First, convert it to base8. You need to take each 64 bit chunk (8 8-bit digits - 1 8-bit digit is an ascii character in size). You also need to know if the encoding was in big, or little endian form. That may require some byte switching to get things correctly decoded. Readable? Good question. In any case, write some code to do the conversion and we can help from there. I don't like being asked to solve homework, or work-work problems for people - that is my business and I am good at it, as well as well-paid for my time to do it! If you make an effort, then I am happy to help you deal with issues you encounter, just as I would for any other engineer in my company.

    Anyway, didn't either of your included links help? Read the manpage on Linux for the base64 command. It isn't hard to use, and will do the work for you - no kitchen time required!

    I just ran it through base64 and got this output:

    Dear Luis,

    Good moning!
    Our Banbase64: invalid input
    I would guess there is an extra bit or byte on the end of the input. So, join all the parts and try using base64 to decode the results.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts