IOS BASE64 Encryption

Source: Internet
Author: User
Tags base64

1, Base64 code description

The BASE64 encoding requires the conversion of 3 8-bit bytes (3*8=24) into 4 6-bit bytes (4*6=24), followed by 6 two in front of 0 bits, forming a 8-bit byte form. If the remaining characters are less than 3 bytes, then 0 is populated with the output character using ' = ', so there may be 1 or 2 ' = ' At the end of the encoded text output.

To ensure the output of the encoded bit-readable characters, BASE64 developed an encoding table for uniform conversion. The size of the encoded table is 2^6=64, which is also the origin of the Base64 name.

2. Base64 Code Table
Code Value character Code Value character Code Value character Code Value character
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 21st 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 /

3, BASE64 encoding use

(1) Use less than three bytes of code

Example: Encryption BS (ASCII b hex 16 binary is 73)

Alternate binary: 0110 0010 0111 0011

Not enough for three bytes with 0 full 0110 0010 0111 0011 0000 0000

Convert to 6 own mode 011000 100111 001100 000000

Find base64 encoding table corresponding to ynm=

(2) Use an encoding greater than or equal to three bytes

For example: Encrypt ASD (ASCII a hexadecimal size s 16 binary to 16 for 64)

Alternate binary: 0110 0001 0111 0011 0110 0100

Convert to 6 own mode 011000 010111 001101 100100

Find base64 encoding table corresponding to Yxnk

IOS BASE64 Encryption

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.