If a plain text is first decrypted (with the AES decryption algorithm) using Key K1 and then encrypted using same K1, would the final result still be the original plain text?
2 Answers
If you are talking about the AES block cipher acting on a one block message, then yes, with K
being the actual 128/192/256 bit-key. For a given key, the encryption E(message, key)
and decryption D(ciphertext, key)
functions are perfect inverses of each other. You will always have both E(D(m,K),K) = m
and D(E(m,K),K) = m
by construction for any block cipher encryption/decryption functions operating on a one-block message m
(for AES one block = 128-bits = 16 bytes).
That said in practice, if you use some well-written tool in a secure mode (like openssl aes-[128|192|256]-cbc
) that internally uses AES as the block cipher for encryption/decryption this probably will NOT work, if you simply feed your tool a plain text message and ask it to decrypt said message with your key.
This is because your tool that uses AES as your block cipher will make various assumptions for you and does more than just apply AES to each block. Specifically:
- The tool will likely add proper padding to your message before encrypting it and will fail to decrypt if you are attempting to decrypt something that wasn't properly padded. (Without proper padding their are attacks against multi-block AES encrypted messages).
- On encryption, the tool may prepend the ciphertext with a block of a random initialization vector (IV); on decryption doesn't attempt to decrypt the zero-th block assumed to be an IV. (Without an initialization vector, an eavesdropper can detect when similar starting messages are being sent and potentially tamper with them).
- The tool also may include some sort of MAC to verify the data wasn't tampered with that will fail if you attempt to decrypt a plaintext message (as the plaintext message would not have a valid MAC that allows decryption to proceed).
-
$\begingroup$ Good answer. I disregarded the fact that the method might affect the output. +1 $\endgroup$– thel3lCommented Mar 26, 2017 at 10:53
The terms 'decrypt' and 'encrypt' in terms of an encryption routine are simply functions - they run an input past a function to retrieve the original content. Generally, they do the exact opposite - if the encryptor flips a bit up, the decryptor will flip the bit down. The original text doesn't matter.
When you decide to run a 'decryption' routine on any text, it'll run the opposite function on the text - but since your input isn't actually encrypted, you'll probably get a stream of absolute garbage. But again, not the point. If you encrypt this garbage output, you should theoretically be able to retrieve your input.
Tl;dr: Yes. It should be possible.