Skip to content

Instantly share code, notes, and snippets.

@CypherpunkSamurai
Last active October 12, 2021 18:30
Show Gist options
  • Save CypherpunkSamurai/2eb418005c4febc3a6ee4717fd11f3fb to your computer and use it in GitHub Desktop.
Save CypherpunkSamurai/2eb418005c4febc3a6ee4717fd11f3fb to your computer and use it in GitHub Desktop.
OpenSSL Quick AES256-CBC

How to encrypt decrypt ASE 256 CBC using Openssl

Prepare input text:

echo "We're blown. Run" >input.txt

Encrypt:

openssl enc -aes-256-cbc -nosalt -e \
        -in input.txt -out input.txt.enc \
        -K '2222233333232323' -iv '5a04ec902686fb05a6b7a338b6e07760'

Decrypt to stdout original text:

openssl enc -aes-256-cbc -nosalt -d \
        -in input.txt.enc \
        -K '2222233333232323' -iv '5a04ec902686fb05a6b7a338b6e07760'

Note 1: for -K and -iv you must pass a string comprised only of hex digits. You can get this string from a binary file like this:

hexdump -e '16/1 "%02x"' FILE_WITH_KEY

Note 2: Here I used AES-256 algo that get key of 256-bit length. But in -K there is only 8 bytes/16 hex/64 bits. In this case openssl pads private key with zeros, so in example above used the following key:

'2222233333232323000000000000000000000000000000000000000000000000'

This is a significant weakening, please use more strong keys in real life. The same story refer to -iv, but it's length depends on chosen algorithm's mode and block length, see related question.

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment