Index  |  Stamped  |  1.1. Base64
La LCO fue actualizada por última vez el 16/may./2026

1.1. Base64

Base64 is an encoding method applied to binary data to represent information obtained as a string of characters in ASCII code. That is, binary information is read in groups of bits, and each group is translated into its ASCII-Base64 representation.

It is primarily used to send information over media designed to handle text, not binary data.

Solución Factible® uses this data processing method to ensure data integrity when received by our servers. Therefore, the information generated as output by the developer or the system will be exactly the same as the information received as input by our system for subsequent processing.

This type of encoding is used in the digital signature element of CFDs (digital tax receipts such as electronic invoices and payment receipts), which will be described in more detail below.

1.1.1. Encoding

If we take the string of characters (String):

Hello world

When encoded in base64, the result is:

SG9sYSBtdW5kbw==

The letters "Hel" in the previously encoded phrase are equivalent to the base 64 encoding: "SG9s", the conversion process is detailed in the table below.

Text H o l
ASCII 72 6F 6C
Patron de bites 0 1 0 0 1 0 0 0 0 1 1 0 1 1 1 1 0 1 1 0 1 1 0 0
Index 18 6 61 44
Base64-Encoding S G 9 s

Table index base64

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

1.1.2. Decoding

To decode the information, a special process must be used. First, every four base64-encoded characters are grouped and realigned as three bytes. However, there are two cases that must be considered at the end of the byte set. If the last characters of the base64-encoded string contain one or two '=' or '==' characters, then the last '=' character must be discarded. If '==' characters are found at the end of the string, then the last two bytes of the sequence must be discarded.

Another important process is to ignore any character in the string that is not valid base64 encoding.

1.1.3. Code Examples

JAVA

import org.bouncycastle.util.encoders.Base64;

public class Main{

    public static void main(String[] args) {
        if (args.length > 0) {
            for (int i = 0; i < args.length; i++) {
                if (args[i].equals("-e") || args[i].equals("--encode")) {
                    String toEncode = args[i + 1] != null && args[i + 1].length() > 0 ? args[i + 1] : "";
                    toEncode = new String(toEncode.getBytes());
                    byte[] data = Base64.encode(toEncode.getBytes());
                    String encoded = new String(data);
                    System.out.println("Resultado de la codificación: " + encoded);
                } else if (args[i].equals("-d") || args[i].equals("--decode")) {
                    String toDecode = args[i + 1] != null && args[i + 1].length() > 0 ? args[i + 1] : "";
                    byte[] data = Base64.decode(toDecode.getBytes());
                    String decoded = new String(data);
                    System.out.println("Resultado de la decodificación: " + decoded);
                }
            }
        }else{
            System.out.println("Nada que hacer... finalizando programa...");
        }
    }
}
                

1.1.4. Tools

Encode

Description: Encode a message in base64.

Decode

Description:decodes a base64 message.

Datos de contacto
comments powered by Disqus