If I do a simple encrypt and decrypt test like so:
echo 'Hello World' | \
openssl enc -aes-128-cbc -pass pass:SeCrEt | \
openssl enc -d -aes-128-cbc -pass pass:SeCrEt
It works fine, it correctly outputs 'Hello World'.
However when I change the blockmode to gcm
and keep everything else the same:
echo 'Hello World' | \
openssl enc -aes-128-gcm -pass pass:SeCrEt | \
openssl enc -d -aes-128-gcm -pass pass:SeCrEt
I'm now getting:
Hello World
bad decrypt
Note the 'bad decrypt', even though it still shows the correct decrypted result.
I've also tried other block modes, they all work fine except GCM. Also changing the key size to 192 or 256 makes no difference. Also adding other parameters (like explicitly specifying -salt
or -pbkdf2
or e.d. -iter 1000
or -md sha512
) make no difference.
Am I doing something wrong, or am I misunderstanding how aes-128/192/256-gcm
is supposed to work?
(edit) regarding @mentallurg's response, I've also tried using files instead of pipes:
echo 'Hello World' > plain.txt
openssl enc -aes-128-gcm -pass pass:SeCrEt -in plain.txt -out cipher.bin
openssl enc -d -aes-128-gcm -pass pass:SeCrEt -in cipher.bin -out decrypted.txt
The latter also gives 'bad decrypt'. Note that decrypted.txt
is created with the correct contents.