Encoding data is a process of converting data from one format into a new format. In the context of web development, there are two main types of encoding: character encoding and data encoding.
HTML Encoding (HTML escape): Special characters (like <
, >
, &
, etc.) in HTML documents need to be encoded to ensure that browsers interpret them corrrectly
<
⇒
>
URL Encoding: When passing data in URLs, special characters that are not allowed in URLs or have a special meaning (such as space or “&”) need to be encoded
space ⇒ %20
& ⇒ %26
https://www.google.com/search?q=嗨妳好 ⇒ https://www.google.com/search?q=%E5%97%A8%E5%A6%B3%E5%A5%BD
encodeURI() and decodeURI()
UTF-8 Encoding: UTF-8 is a character encoding that represents each character in the Unicode character set. It is widely used for encoding text on the web to support internationalization and multilingual content.
Base64 Encoding: This is a binary-to-text encoding scheme where binary data is encoded using a set of 64 characters, consisting of letters, digits, and symbols. It is commonly used for encoding binary data, such as images or files, into a text format that can be transmitted over text-based protocols like email or included in data URLs.
cat image.png | base64
Encode an image with base64
Form Data Encoding: When submitting form data in an HTTP request, the data is usually URL-encoded or sent as multipart/form-data, depending on the content type specified in the request.
The symmetric key cryptography method uses the same key for encrypting and decrypting.
pros and cons
The asymmetric key method uses two different keys (the public key and the private key) to encrypt and decrypt data.
pros and cons