AES Encryption
A customized AES encryption and decryption script for steganography
Before diving into any method, I should explain what encryption is and why we use it for steganography.
Introduction: What is Encryption?
Encryption is the process of transforming readable data into an unreadable format using a secret key. In simple terms, if we have a message like "Hey this is kaizoku writing an article on steganography tool", you can read this without any issue. But what if i encrypt it? This means I convert the message into something else like: GhxVoYmGbY6bnNNtzg2VgyQkyNthn1umIGpe6zTlSvzPZ0TcRPHCddqcoBDhLPeloUKgNNnOYPrj1tUKyJmo8g==
Can you even read it? It's unreadable, and on the top of that, I used a key to encrypt this message. Nobody can decrypt this message without the key.
This protects the data from unauthorized access, meaning only someone with the correct key can decrypt and read it. Think of it like locking a message in a safe. Without the right combination, it remains unreadable.
I will explain how tol encrypt the payload before embedding it in media file or decrypt it after extraction.
Why use encryption before steganography?
Steganography hides the existence of data, while encryption hides the meaning of data.
Think of it like: you want to send a valuable letter to a friend, so you hide the letter inside a normal looking box of cookies. To anyone else, it looks like an ordinary package, no one will suspects a letter is inside. This is steganography: you hide the letter in a box of cookie so no one can realize it's there.
Now, suppose someone opens the box of cookie and finds the letter? that's why encryption plays an important role. Before you hide the letter in box, you write it in secret code so no one other than your friend can understand what's the content of the letter.
By combining both steganography and cryptography, we create layered security where one protects the visibility and the other protects the contents.
It adds a second layer of protection.
It prevents meaningful extraction
It prevent sensitive metadata leakage.
Steganography without encryption is like whispering a secret in a quiet room — someone might still overhear you.
What is AES?
AES stands for Advanced Encryption Standard. It's one of the most widely used and trusted encryption algorithms in the world. This is symmetric encryption which means it uses the same key for encryption and decryption. Yes , there are encryption methods that uses different keys for encryption and decryption like RSA, it has 2 keys public and private. However, we are not here to learn about other type of encryption. Back to AES: there are different type of key sizes AES uses which are 128, 192 and 256 bits. The more bits, the stronger the security. Why did I choose AES over other encryption algorithms? It's suitable for our steganography tool because same key encrypts and decrypts the payload(secret data). It's fast, efficient, strong and modern. We will use EAX mode, which ensure integrity.
Why EAX mode? EAX stands for Encrypt-then-Authenticate-then-Translate. It provides confidentiality and Integrity which detects tampering or corruption. This mean if someone alters the encrypted data, the decryption will fail — you will know its been tampered with.
What are modes in AES? AES by itself only encrypts a single 128 bit block. To handle complete files or messages, we use modes of operation that define how to process longer data. There are other mode besides EAX such as, CBC, ECB, GCM , etc. All modes have their downsides, but EAX, its only one which is secure, simple and well supported in python
This should be sufficient explanation of what encryption is and how it works. Let's move on to the script we will use in all steganography methods: LSB for image, LSB for audio, Phase coding for audio and histogram for images.
Make sure to install module before using script:
Implementation
We import here hashlib and AES from Crypto.Cipher module.
Our first function, derive_key() takes only 1 argument which is our key and it converts our key (whatever is it) into 32-byte AES key by using SHA-256 hashing to ensure consistent.
Next, we have to_seed() function, which takes our key as it only argument and convert it to a large integer(seed) which is going to be use for randomization of pixels, frames and phases later. It also uses SHA-256 hashing but returns the digest as an integer. for example, if we use "hey" as our key, the output of to_seed() function would be:
113263810512265783576553413508848914573674345708076686225007375315110865736196
Now, lets discuss the encryption function that encrypts our secret file/message data. This function encrypts any binary payload using AES encryption in EAX mode, which provide security and supports integrity verification. As you can see, we take 2 arguments for this function: bytes of our secret file/message and the key. The derived key is used to initialize an AES cipher in EAX mode (which handles both encryption and authentication). AES internally uses this key to securly mix the bits and encrypt the data. The next line, "cipher.encrypt_and_digest(payload)" which produces ciphertext (the encrypted secret) and a tag which is used to verify that data hasn't been tampered with.
The final function of this script is decryption() function which takes 2 arguments: the key and the payload(encrypted bytes) extracted from stego file. The key is used to recreate the AES cipher, this is crucial here if the key is even slightly different, it can lead the decryption into failure because tag verification won't match which indicates a wrong key. what does the decryption function actually do? It extracts the nounce, tag and ciphertext from encrypted bytes , reconstructs the AES cipher using same key. If the key is correct, it verifies the tag, decrypts the ciphertext and returns the secret file which was embedded in the cover file.
Last updated