• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

How to encode and decode the strings with base64

February 16, 2013 by Sharad Chhetri 1 Comment

In this post we will learn how to encode and decode the strings with base64. We will also see some example on this as well.

Introduction

Base64 is a group of similar encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation. The Base64 term originates from a specific MIME content transfer encoding.

Base64 encoding schemes are commonly used when there is a need to encode binary data that need to be stored and transferred over media that are designed to deal with textual data. This is to ensure that the data remain intact without modification during transport. Base64 is commonly used in a number of applications including email via MIME, and storing complex data in XML.

Encode and Decode strings with base64 in linux/unix system

First install the openssl in your linux system.

    In CentOS or Redhat
yum install openssl
    In Debian or Ubuntu
sudo apt-get update
sudo apt-get install openssl

Note: In Ubuntu 16.04 LTS or above Operating system you can replace the command with apt-get to apt only. Now the command should be run in given below format.

sudo apt update
sudo apt install openssl

For eg. We are using a string called Mypers0nalbl0g@sh@radchh3tr1.coM

Encode The String With base64
Use the given below command to encode the string with base64.

sharad@mylaptop:~$ echo Mypers0nalbl0g@sh@radchh3tr1.coM|openssl base64
TXlwZXJzMG5hbGJsMGdAc2hAcmFkY2hoM3RyMS5jb00K
sharad@mylaptop:~$ 

Decode The Same String With base64
Use the given below command to decode The same string with base64

sharad@mylaptop:~$ echo "TXlwZXJzMG5hbGJsMGdAc2hAcmFkY2hoM3RyMS5jb00K" |openssl  base64 -d
Mypers0nalbl0g@sh@radchh3tr1.coM
sharad@mylaptop:~$

Use of base64

Base64 can be used for various purpose.
Disclaimer:The given below information source is taken from Wikipedia.

1. Base64 can be used to transmit and store text that might otherwise cause delimiter collision
2. Spammers use Base64 to evade basic anti-spamming tools, which often do not decode Base64 and therefore cannot detect keywords in encoded messages.
3. Base64 is used to encode character strings in LDIF files
4. Base64 is often used to embed binary data in an XML file, using a syntax similar to … e.g. favicons in 5. Firefox’s exported bookmarks.html.
5. Base64 is used to encode binary files such as images within scripts, to avoid depending on external files.
6. The data URI scheme can use Base64 to represent file contents. For instance, background images and fonts can be specified in a CSS stylesheet file as data: URIs, instead of being supplied in separate files.
7. The FreeSWAN ipsec implementation precedes Base64 strings with 0s, so they can be distinguished from text or hexadecimal strings.
8. Although not part of the official specification for SVG, some viewers can interpret Base64 when used for embedded elements, such as images inside SVG

Share this:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. awk command to search keyword or strings in file
  2. sed command to display text between two strings or keywords
  3. grep command to find multiple strings or keyword from file
  4. Convert hyphen to underscore in between all filenames shell script
  5. How to change login banner message in GUI mode in CentOS 6 or above version.
  6. Eject Command: Eject DVD-ROM Or CD-ROM In Linux
  7. WordPress host IP changed not able to open wp-admin and site page looks scattered
  8. How to use grep command to get fixed pattern or exact keyword
  9. How to see line numbers in file through cat command
  10. Convert video file into gif file through command line in linux

Filed Under: Linux, Tips And Tricks Tagged With: encode decode base64

Reader Interactions

Comments

  1. base64 says

    June 18, 2013 at 9:16 am

    also you can use the base64 -d command in linux

    anyway, great tutorial

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

How to convert rpm file into deb file

Allow only members of Wheel group to use su command on RHEL/CentOS

Error: Could not stat() command file ‘/var/lib/nagios3/rw/nagios.cmd’!

How to use grep command to get fixed pattern or exact keyword

Forward all incoming emails to other SMTP server or gateway

curl command to check the http status

Edit the crontab without using crontab -e

Explore 90+ Article On "Linux Tips And Tricks"

Copyright © 2023 ·
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From Bharat.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy