Encoding, Encryption, and Hashing
Tags: security, programming, webdev
Published: 2022-03-15 19:15:01

### What are the differences between Encoding, Encryption, and Hashing? Learn the differences.

### <br>

Sometimes people use the terms encryption and encoding interchangeably. Also, often hashing is called into play as an encryption mechanism. Confusing these concepts may lead to misunderstandings in the way security is implemented.

Let's take a high-level overview of these concepts and clarify the differences.

If you prefer watching videos, here is a video version of this article:

{%youtube -bAnBzvMLig%}


## What Is Encoding?

Let's start with encoding. You can define it as **a technique to transform data from one format to another so that it can be understood and consumed by different systems**.

Basically, encoding has to do with information representation. When you have some information, say the [name of the mineral that weakens Superman](https://en.wikipedia.org/wiki/Kryptonite), you can represent it through letters, as in *kryptonite*. This is a handy representation for humans but not so easy for being manipulated by computers. What usually happens, in this case, is the transformation of this sequence of characters into a sequence of bits like this:

```
01101011 01110010 01111001 01110000 01110100
01101111 01101110 01101001 01110100 01100101
```

You have two representations for the same information. The letter-based representation is usually understood by *human systems*; the bit-based representation is more suitable for computer systems. Commonly, you say that the sequence of letters has been *encoded* into a sequence of bits.

So, encoding is just a transformation from one data representation to another, keeping the same information. Usually, it involves a conversion table, such as an [ASCII table](https://en.wikipedia.org/wiki/ASCII) in our example, that maps a representation item in one system to the corresponding representation item in the other system.

You can find several encoding mechanisms out there. To mention just a few in the character encoding space, apart from the dear old ASCII, you have:

- [Unicode](https://en.wikipedia.org/wiki/Unicode), which allows you to represent more complex items than letters, such as emoji and other symbols.
- [Base64](https://en.wikipedia.org/wiki/Base64), which lets you represent binary data, such as an image, through text.
- [URL encoding](https://en.wikipedia.org/wiki/Percent-encoding), useful to represent arbitrary data in an URL, where some characters are reserved or cannot be used (think of spaces or colons, for example).

Consider [JSON Web Tokens (JWT)](https://jwt.io/introduction), for example. The three parts that compose a token are encoded using [Base64-URL](https://www.rfc-editor.org/rfc/rfc4648#section-5), a variant of Base64 encoding combined with URL encoding. The following is an example of encoded JWT:

```
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwOi8vbXktZG9tYWluLmF1dGgwLmNvbSIsInN1YiI6ImF1dGgwfDEyMzQ1NiIsImF1ZCI6IjEyMzRhYmNkZWYiLCJleHAiOjEzMTEyODE5NzAsImlhdCI6MTMxMTI4MDk3MCwibmFtZSI6IkphbmUgRG9lIiwiZ2l2ZW5fbmFtZSI6IkphbmUiLCJmYW1pbHlfbmFtZSI6IkRvZSJ9.bql-jxlG9B_bielkqOnjTY9Di9FillFb6IMQINXoYsw
```

You can see the decoded version of this JWT using the [jwt.io](https://jwt.io/?id_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwOi8vbXktZG9tYWluLmF1dGgwLmNvbSIsInN1YiI6ImF1dGgwfDEyMzQ1NiIsImF1ZCI6IjEyMzRhYmNkZWYiLCJleHAiOjEzMTEyODE5NzAsImlhdCI6MTMxMTI4MDk3MCwibmFtZSI6IkphbmUgRG9lIiwiZ2l2ZW5fbmFtZSI6IkphbmUiLCJmYW1pbHlfbmFtZSI6IkRvZSJ9.bql-jxlG9B_bielkqOnjTY9Di9FillFb6IMQINXoYsw) debugger.


[Read more...](https://auth0.com/blog/encoding-encryption-hashing/?utm_source=content_synd&utm_medium=sc&utm_campaign=security)