URL encoding and decoding tools

Introduction

This article briefly introduces a codec tool that supports URL encoding and decoding, Base64 encoding and decoding.

Official website address: https://smart-tools.cn/dev/encoder/app

background

URL encoding

URL encoding is the encoding used by the browser when sending data to the server. It is an encoding algorithm, not an encryption algorithm. Its purpose is to encode any text data into text represented by the % prefix. The encoded text only contains A~Z, a~z, 0~9 and -_.*. The purpose of this is to facilitate browser and server processing. . For example, < is represented by %3C. To help everyone understand, let’s give a more specific example.

Original http request:https://mock.smart-tools.cn/mocktaildemo?name=谭杰

Encoded request:https%3A%2F%2Fmock.smart-tools.cn%2Fmocktaildemo%3Fname%3D%E8%B0%AD%E6%9D%B0

We found that except for English letters and numbers, everything started with %. Since a Chinese character is represented by 3 bytes, "Tan Jie" is represented by 9 %xx.

Base64 encoding

We know that the email protocol is a text protocol. If we want to add a binary file to the email, we can convert the binary file into text through Base64 encoding, otherwise garbled characters will appear.

Base64 encoding is an encoding algorithm that represents binary data as text. It only contains 64 characters, as shown below: ['A', 'B', 'C', ... 'a', 'b', 'c', ... '0', '1', ... '+', '/'].

The corresponding indices of Base64 range from 0 to 63 respectively. Since Base64 can only display 64 kinds of text characters, for binary data, it needs a mapping mechanism to convert binary data into text data, that is, select 3 bytes as a group and regroup: every 6 bits For a new byte, form 4 groups. What if the binary data to be encoded is not a multiple of 3, and there will be 1 or 2 bytes left in the end? After Base64 pads \x00the end with bytes, then adds 1 or 2 =numbers at the end of the encoding to indicate how many bytes are padded, which will be automatically removed during decoding.

Since the original 3 bytes are changed into 4 bytes, which means that the length is increased by 33%, the transmission efficiency is reduced. Currently, we apply Base64 to common applications that transmit a small amount of binary data, such as cookies and URLs. wait.

product

In this section, we introduce the use of encoding and decoding tools in the Smart-tools toolbox to perform URL and Base64 encoding and decryption of text.

Example 1: URL encoding and decoding

Example 2: Base64 encoding and decoding

Summarize

In this article, we briefly introduce the specific meaning of URL encoding and Base64 encoding. At the same time, it introduces how to encode and decode URLs and Base64 strings based on the encoding and decoding tools in the Smart-tools toolbox.

Guess you like

Origin blog.csdn.net/tanjie_123/article/details/126977328