Suppose I wrote a function $$(salt,IV ) = \text{keyIVGenerator}(passwd)$$ which generates a random salt of size 32-bytes and a random Initialisation Vector (IV) of size 16-bytes. Then, use a Key Derivation Function (KDF) like PBKDF2 to generate a key of length 32 bytes (dkLen=32).
$$key = PBKDF2(password, salt, deLen)$$
I created a function $$ c = encryption(key,data,IV)$$, assume that padding of data (using aes CBC) is correctly done and logic is right.
When I ask the user for encryption and data, I pass the password to the function $keyIVGenerator(passwd)$ to get the $IV,key$, and $passwd$ them to the $encryption(key,data,iv)$ along with data. The encryption works.
And now suppose I have to decrypt the data I will need to pass the same key as generated by PBKDF2 for encryption to decrypt my data. The iv was prepended to the ciphertext.
But what about the salt.
If I pass the password requested from the user to $keyIVGenerator(passwd)$ it will generate a new key with the new random salt, hence the data won't be decrypted.
Am I supposed to prepended my salt to the ciphertext too? Should I keep a database of salts?
How do I generate the same key from PBKDF2?