In openssl we can use the following commands to encryptdecry
In openssl, we can use the following commands to encrypt/decrypt a file.
$openssl enc -aes-256-ecb -nosalt -e -in plain.txt -out cipher.bin
(use AES-256-ECB to encrypt the file plain.txt and store the ciphertext as cipher.bin)
$openssl enc -aes-256-ecb -nosalt -d -in cipher.bin
(use the same scheme to decrypt the ciphertext cipher.bin)
\"-aes-256-ecb\" option specifies the version of the AES algorithm which uses 256-bit keys.
a. The encryption algorithm aes-256-ecb is a 128-bit block cipher. Design an experiment to verify it.
b. Create a >64 bytes text file plain.txt and use the above command to generate the cipher.bin. Use the ghex2 or hexedit utility to change 1 bit of cipher.bin and save the result as cipher1.bin. Execute the same command above to decrypt cipher1.bin. How much information can you recover? Explain why.
Solution
1) we consider the ciphertype as
% openssl enc ciphertype -e -in plain.txt -out cipher.bin \\
-K 00112233445566778889aabbccddeeff \\
-iv 0102030405060708
we can verify using man command
here you can replace ciphertype with -aes-128-cbc, -aes-128-cfb,-bf-cbc
2)
% openssl rand -base64 16 > symm_key
it generates 16 byte random value in 64. we will use this as follows
% openssl enc ciphertype -e -in plain.txt -out cipher.bin \\
-pass file:symm_key -salt
if the plain is to be encrypted which is not multiple we need to pad before encrypting and the decypting need to know how to remove the padding.
