2

It's clear how the algorithm manages plain text as the characters byte values to the state matrix.

But what about AES encryption of binary files?

How does the algorithm manages larger than 16 bytes files, as long as the state is standarized to be 4x4 bytes?

4

2 回答 2

2

The AES primitive is the basis of constructions that allow encryption/decryption of arbitrary binary streams.

AES-128 takes a 128-bit key and a 128-bit data block and "encrypts" or "decrypts" this block. 128 bit is 16 bytes. Those 16 bytes can be text (e.g. ASCII, one character per byte) or binary data.

A naive implementation would just break a file with longer than 16 bytes into groups of 16 bytes and encrypt each of these with the same key. You might also need to "pad" the file to make it a multiple of 16 bytes. The problem with that is that it exposes information about the file because every time you encrypt the same block with the same key you'll get the same ciphertext.

There are different ways to build on the AES function to encrypt/decrypt more than 16 bytes securely. For example you can use CBC or use counter mode.

Counter mode is a little easier to explain so let's look at that. If we have AES_e(k, b) encrypt block b with key k we do not want to re-use the same key to encrypt the same block more than once. So the construction we'll use is something like this: Calculate AES_e(k, 0), AES_e(k, 1), AES_e(k, n)

Now we can take arbitrary input, break it into 16 bytes blocks, and XOR with this sequence. Since the attacker does not know they key they can not regenerate this sequence and decode our (longer) message. The XOR is applied bit by bit between the blocks generated above and the cleartext. The receiving side can now generate the same sequence, XOR it with the ciphertext and retrieve the cleartext.

In application you also want to combine this with some sort of authentication mechanism so you something like AES-GCM or AES-CCM.

于 2013-07-14T06:50:30.750 回答
1

Imagine you have a 17 byte plain text. state matrix will be filled with the first 16 bytes and one block will be encrypt. Next block will be 1 byte that left and state matrix will be padded with data in order to fill those 16 bytes AES needs.

It works well with bytes/binary files because AES always consider bytes unities.Does not matter if that is a ascii chunk or any other think. Just remember that everything in a computer is binary/bytes/bits. Once data be a stream data (chunks of information in bytes) it'll work fine.

于 2015-06-13T03:07:48.793 回答