Cryptography - Base64 Cipher

About

Base64 is a cipher (without key and reversible) that converts (encode) a data (message) in 64 characters of the ASCII string.

Decoder / Encoder

See also the Google encoder/decoder

Usage

  • datastore accept only ASCII string format
  • to have a portable version of the data between system. ie get rid of:
  • having data encoded on only 64 characters (ie without the point for instance)

Steps

Encode

A text message with only string
  • Transform the text into binary data by applying the character set table conversion
  • Transform the binary into a succession of characters with the alphabet conversion table
  • add the optional trailing character =
  • and you get the base64 cipher

Syntax

base64Conversion=

where:

  • base64Conversion is the conversion when the alphabet conversion is applied
  • = is one or several optional trailing character

Alphabet

The alphabet is the conversion table between:

base64url (base64 for URL) replaces:

  • the + with -
  • and / with _

because + and / are characters that have meaning in a URL

Binary Number Base 64 Number Character Base64 Character Base64Url
0000 0 A A
0001 1 B B
0010 2 C C
0011 3 D D
0100 4 E E
0101 5 F F
0110 6 G G
0111 7 H H
1000 8 I I
1001 9 J J
1010 10 K K
11 L L
12 M M
13 N N
14 O O
15 P P
16 Q Q
17 R R
18 S S
19 T T
20 U U
21 V V
22 W W
23 X X
24 Y Y
25 Z Z
26 a a
27 b b
28 c c
29 d d
30 e e
31 f f
32 g g
33 h h
34 i i
35 j j
36 k k
37 l l
38 m m
39 n n
40 o o
41 p p
42 q q
43 r r
44 s s
45 t t
46 u u
47 v v
48 w w
49 x x
50 y y
51 z z
52 0 0
53 1 1
54 2 2
55 3 3
56 4 4
57 5 5
58 6 6
59 7 7
60 8 8
61 9 9
62 + -
0011 1111 63 / _

Management

Javascript

With atob / btoa Javascript Function, see the decoder/encoder script above.

Ref:

base64 utility

cat my-file | base64

Open Ssl

Openssl

echo Hello World ! | openssl base64
SGVsbG8gV29ybGQgIQo=

Java

String encode = Base64.getEncoder().encodeToString("Nico".getBytes());
byte[] decode = Base64.getDecoder().decode(encode);
System.out.println(new String(decode,StandardCharsets.UTF_8));
Nico

Documentation / Reference

  • rfc4648 - The Base16, Base32, and Base64 Data Encodings

Powered by ComboStrap