

Base64 Encoding
source link: https://shannoncrabill.com/blog/base64-encoding-mac-terminal/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

While browsing some API documentation, I saw references to Base64 for passing credentials to the API. I had seen Base64 referenced a few times, but had no idea how to convert text into Base64. So, I did some digging. This post will outline how to encode (and decode) text into Base64 using the MacOS Terminal.
What is Base64?
I should share a little bit about what base64 is. The MDN documentation explains the overarching concept of Base64 is.
Base64 is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation.
You can think of Base64 is another way to represent binary or text data.
The conversion process is somewhat detailed, and I encourage you to check out the resources at the bottom of this article if you are curious about the benefits and technical details of Base64.
Converting Text into Base64
While reading those API docs, I had no idea to create a Base64 string.
There are converters a few Google searches away. But, did you know there’s a Base64 command built into the MacOS?
To turn a string into Base64, open a new Terminal window, and use this format.
base64 <<< string
That would be base64
followed by a space, three less-than signs (<
), another space, then whatever string
you want to encode in Base64.
Here’s an example:
If I wanted to convert the string I love cheeseburgers
into Base64, I would enter this:
base64 <<< "I love cheeseburgers"
Which would print out SSBsb3ZlIGNoZWVzZWJ1cmdlcnMK
as a result.
You only need quote marks around the string you would like to convert, if it has space it in.
The following does not need quote marks, for example:
base64 <<< ilovecheeseburgers
Decoding Base64
With a similar command, you can decode Base64 back into human, readable text.
Let’s say a friend of ours sent us the following code:
SSBsb3ZlIHlvdSBtb3JlCg==
To decode Base64, we add a -D
flag before the three arrows and after base64
.
Like this:
base64 -D <<< SSBsb3ZlIHlvdSBtb3JlCg==
Which returns I love you more
. How sweet!
Base64 is Not Unique
While a Base64 string like SSBsb3ZlIGNoZWVzZWJ1cmdlcnMk
looks random, it is not.
Each time I run base64 <<< "I love cheeseburgers"
it’ll return the same result. If you run the same code, you’ll get the same result. And since a Base64 string can be decoded, it’s not appropriate for hashing passwords, storing API keys, etc.
Resources
Related
Recommend
-
112
对称加密和Base64编码
-
7
The Oracle documentation for java.util.Base64 refers to three different kinds of Base64, but only by reference to RFCs. Here it is in one place.
-
13
Base64 Encoding and Decoding in JavaScript in Adobe AIR Thursday, June 12, 2008 I have been working on a JavaScript AIR app for the past week or so while on the on AIR Tour in Europe, and ran into the need to Base64 enc...
-
11
January 14, 2021 Base64 Encoding With C# ...
-
12
S M Firoz Ashraf November 26, 2021 2 minute read
-
6
Base64 Encoding and Decoding Using Pythonby Abder-Rahman AliMar 22, 2016(Updated Apr 11, 2022)Read Time:9...
-
7
Cryptopals Crypto Challenges These are solutions to the Cryptopals Crypto Challenges, solved using C# and .NET Core. These articles talk through the theory and code snippets that I found most...
-
7
Encoding Base64/32/16 encoding/decoding for React Native written in C/C++ and JSI May 17, 2022 1 min read
-
6
Base64 encoding: What sysadmins need to know By understanding Base64 encoding, you can apply it to Kubernetes secrets, OpenSSL, e...
-
7
How to upload files from your HTML form using Base64 encodingDecember 22, 2021 · 5 min readMelih EkinciFrontend...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK