Image Encryption and Decryption Using AES

Version 1.0.1 (19.1 KB) by David Hill
Image encryption and decryption using AES and the Galois Counter Mode (GCM) Block Cipher


Updated 24 Feb 2022

View License

Image encryption/decryption using AES and the Galois Counter Mode (GCM) Block Cipher. Accepts AES secret key lengths of 128,192,256 (hexidecimal). Implimentation is based on NIST Special Publication 800-38D.
Inputs: secretKey - AES secret key, hexidecimal (128,192, or 256 bits), iv - initialization vector (random 96-bit hexidecimal), imageFile - string of file name (i.e., 'AES_image.jpg'), aad - additional authenticated data (plaintext string).
Outputs: outputCipher - uint8 encrypted matrix of same size as input image, authTag - authentication tag (hexidecimal).
Inputs: secretKey (same as above), iv (same as above), outputCipher - encrypted uint8 matrix of image (same size as original), aad - additional authenticated data (plaintext string) must match encrypted aad string, authTag (same as above output).
Outputs: ImageOut - decrypted uint8 matrix (same as original image that can be uiwriten to whatever output format), authTagResult - either true or false (true is decrypted correctly, i.e. authentication tag match)
The initialization vection is not generated by the code and must be provided. It is extremely important that the initialization vection be different for each encryption using the same secret key (see NIST publication for explanation). Depending on the size of the image, encryption/decryption times can be several minutes long.
[outputCipher,authTag]=ImageEncryption(secretKey,iv,'AES_image.jpg','AES image');
[ImageOut,authTagResult]=ImageDecryption(secretKey,iv,outputCipher,'AES image',authTag);

Cite As

David Hill (2023). Image Encryption and Decryption Using AES (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2021b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Changed description