Base64 Encoder & Decoder
Convenient and fast online Base64 encoding and decoding services.
Programming languages for Base64 methods: | |
---|---|
JavaScript | //encode window.btoa('str') //decode window.atob('base64') |
Python | import base64; //encode base64.b64encode(); //decode base64.b64decode(); |
Java | import java.util.Base64; //encode byte[] binaryData = "hello world".getBytes(); String encodedData = Base64.getEncoder().encodeToString(binaryData); //decode String encodedData = "aGVsbG8gd29ybGQ="; byte[] binaryData = Base64.getDecoder().decode(encodedData); |
Go | import ( "encoding/base64" ) //encode base64.StdEncoding.EncodeToString(binaryData) //decode base64.StdEncoding.DecodeString(encodedData) |
C++ | #include "b64/encode.h" //encode base64::encoder enc; enc.encode(binaryData, sizeof(binaryData), encodedData); //decode base64::decoder dec; dec.decode(encodedData, encodedData.size(), binaryData); |
Swift | import Foundation //encode let binaryData = "hello world".data(using: .utf8)! let encodedData = binaryData.base64EncodedString() //decode let encodedData = "aGVsbG8gd29ybGQ=" let binaryData = Data(base64Encoded: encodedData)! let decodedString = String(data: binaryData, encoding: .utf8)! |
PHP | //encode base64_encode('str') //decode base64_decode('base64') |
C# | //encode System.Convert.ToBase64String(binaryData); //decode byte[] binaryData = System.Convert.FromBase64String(encodedData); string decodedString = System.Text.Encoding.UTF8.GetString(binaryData); |
Ruby | require 'base64' //encode Base64.encode64(binaryData) //decode binaryData = Base64.decode64(encodedData) decodedString = binaryData.force_encoding('UTF-8') |
The importance of data encryption
Data encryption can improve data security, so that even if the data is stolen, hackers cannot directly access the data, thereby reducing the risk of data leakage and loss.
Base64 algorithm
The Base64 algorithm converts 8-bit binary data into 6-bit Base64 characters, so that binary data can be transmitted or stored in ASCII strings. The core of the Base64 algorithm is to divide the original binary data into 6-bit groups, and then convert each 6-bit binary number into a corresponding Base64 character.
The implementation steps of the Base64 algorithm are as follows:
1. Divide the original binary data into groups of 6 bits. If the last group is less than 6 bits, add 0 at the end to make the length a multiple of 6.
2. Convert each 6-bit binary number to the corresponding Base64 character. The Base64 character set includes 64 characters that can be represented using numbers, uppercase and lowercase letters, and two special characters (+ and /).
What is Base64?
Base64 is a data encoding method that converts arbitrary binary data into printable ASCII characters. Base64 encoding can convert invisible binary data into visible characters for transmission or storage on the network without changing the content of the original data.