2

When using openssl version 1.0.2m, I encrypted my test file as follows:

openssl enc -aes-256-cbc -salt -in test.txt -out test.txt.enc

Just entering password, that's what I wanted.


Now, the question is, when decrypting the file, will I in the future need this salt or whatever that is? Or I don't really understand where is that salt stored.

2 Answers 2

2

The salt (or IV, initialization vector) is just used to randomize the encryption. Without one, identical inputs lead to identical outputs, which leaks information (namely the fact that the messages are the same). I think I've mostly seen it called "salt" in connection with password hashing, and usually IV in encryption, but the idea is the same. See e.g. Salt_(cryptography) and Initialization vector on Wikipedia. crypto.stackexchange.com and security.stackexchange.com would also have more information on both.

The salt is stored in the output file, so you don't need to save it explicitly. You can see that the output file is smaller if you give the -nosalt flag instead.

2

The ilkkachu answer is misleading. Salt and IV have two completely different purposes

These purposes are described in the linked Wikipedia pages

Salt is used for key derivation. Hashing is used to created a fixed length encryption key from the user-supplied passphrase. The purpose of the salt is to avoid creating the same key from the same passphrase, to protect against rainbow table attacks. The passphrase and salt are concatenated, then hashed

The initialization vector has a different purpose. The AES cipher transforms (encrypts) a fixed number of bits (block) of plaintext using a fixed-length key and the contents of the previous block of plaintext. The first block does not have a previous block, so it is encrypted using the IV and the key

The salt is usually stored near the beginning of the encrypted file. It is not secret

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.