DEV Community

Ky Huynh
Ky Huynh

Posted on

1 1

How to encode and decode file to base64 offline

Although there are a number of websites that allow to convert file to base64 and vice versa. However, it could leads to data leak issue if these data from your working project.

Therefore, I would like to introduce a tip to convert file to base64 (and vice versa) offline.

1) Encode file (ex: pdf) to base64:

base64 -w 0 test1.pdf

Image description

2) Encode a file to base64 and write it to file:

base64 -w 0 test1.pdf > test1.txt

3) Decode base64 to file:

base64 -d test1.txt > test1.pdf

Tool need to use:

  1. Linux: use the default cmd
  2. Window: use the git bash which I believe all the developers already installed

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay