BASE64 encoding for Secure URLs

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Previous research and analysis of URL compression (continued) introduced the BASE62 algorithm, a hash algorithm similar to Base64. Today found another optimization of the Base64 algorithm, and reference to the next Golang source, in the encoding/base64/base64.go inside.

const encodeStd = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

The traditional Base64 is a-Z, A-Z, 0-9, plus + and/, a 64-coded string.

However, the standard Base64 is not suitable for direct transmission in the URL, because the URL encoder will be in the standard Base64 "/" and "+" characters into the form of "%XX", and these "%" number in the database will need to be converted, because ANSI SQL has the "%" Used as a wildcard character.

To solve this problem, a modified Base64 encoding for URLs is used, which does not populate the ' = ' at the end, and the "+" and "/" in standard Base64 are changed to "-" and "_" respectively, thus eliminating the conversion required for URL codec and database storage. Avoids the increase in the length of encoded information in this process, and unifies the format of object identifiers in databases, forms, and so on.

The Base64.go file also defines a Base64 algorithm dedicated to URL security in URLs.

const encodeURL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"

Replaced the previous plus sign with a minus sign, and the slash was underlined.

For this reason, I found that one of my coding results and should get only one bit, one is a plus, one is a minus. Because if the code string different reasons, even if it is a difference, the result is completely different, poor one certainly not because of this. The original is so, understand or too little ...

###### References + Base64-wikipedia

Original link: Security URL Base64 Encoding, reproduced please specify the source!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.