Current location - Quotes Website - Signature design - IOS AES encryption
IOS AES encryption
Aes: (Advanced Encryption Standard) Advanced Encryption Standard. Is a symmetric block key algorithm, which aims to replace DES as a widely used standard.

There are three key lengths, namely AES- 128, AES- 192 and AES-256.

There are four encryption modes, namely ECB (Electronic Codebook), CBC (Cipher Block Linking), CFB (Cipher Feedback Mode) and OFB (Output Feedback).

Fill mode:

Because block encryption can only encrypt data blocks of a specific length, CBC and ECB modes need to fill in data before encrypting the last data block. (In CFB, OFB and CTR modes, there is no need to fill the last plaintext, because the encryption operation with the key is the last encrypted ciphertext. )

The iOS SDK provides PKCS7Padding, while JDK provides PKCS5Padding. In principle, pkcs5packing limits the size of the filled block to 8 bytes, while in Java, when the block is larger than this value, its pkcs5packing is equal to PKCS7Padding.

Initial vector (offset)

To use other encryption modes except ECB, you need to pass in an initial vector with the size equal to the block size (the block size of AES is 128 bits (16 bytes)). The API documents of both platforms indicate that when the initial vector is not passed in, the system will use an all-zero initial vector by default.

Key length, encryption mode, padding mode, initial vector (also called offset, not needed in ECB mode)

AES encryption: Data need to be grouped, and each group 16 bytes, less than 16 bytes, needs to be filled according to different filling methods. The length of the key can be 128 bits (16 bytes), 192 bits (24 bytes) and 256 bits (32 bits). Since the offset iv is used for XOR operation with the first group of data, the length should be consistent with the length of each group, and the length is 16 bytes.

Comics: What is AES algorithm?

Comics: the basic principle of AES algorithm

AES encrypts synchronization between IOs and Java.

IOS AES encryption (mainly using CFB mode)