aes-eiffel is an Eiffel implementation of the Advanced Encryption Standard (AES) algorithm, based on the tiny-AES-c C implementation. This library provides a simple and efficient way to perform AES encryption and decryption in Eiffel applications.
- Supports AES-128, AES-192 and AES-256 encryption and decryption.
- Implements three modes of operation:
- ECB (Electronic Codebook)
- CBC (Cipher Block Chaining)
- CTR (Counter)
- Provides string-based operations for easy encryption and decryption of text
- Includes PKCS7 padding for block alignment
- Designed for simplicity and ease of use
The library provides three main methods for each mode of operation:
-
ECB Mode:
ecb_encoding_string(plaintext, key): STRING
ecb_decoding_string(ciphertext, key): STRING
-
CBC Mode:
cbc_encoding_string(plaintext, key, iv): STRING
cbc_decoding_string(ciphertext, key, iv): STRING
-
CTR Mode:
ctr_encoding_string(plaintext, key, nonce): STRING
ctr_decoding_string(ciphertext, key, nonce): STRING
Example usage:
local
aes: AES
key, plaintext, encrypted, decrypted: STRING
do
create aes.make
key := "Sixteen byte key"
plaintext := "Hello, World!"
encrypted := aes.ecb_encoding_string(plaintext, key)
decrypted := aes.ecb_decoding_string(encrypted, key)
check plaintext.is_equal(decrypted) end
end
- CTR (Counter) mode is generally considered more secure and preferable compared to ECB and CBC modes.1
- ECB mode is the least secure and should be avoided for most use cases, especially for data larger than a single block.3
- CTR mode offers advantages over CBC:
- Key security considerations:
- While CTR is generally more secure than CBC or ECB, combining CTR with a proper authentication mechanism or using an authenticated encryption mode like GCM is the most secure approach.8
- Always use a secure method to generate keys and IVs/nonces.9