I'm a bit new to cryptography and I'm trying to wrap my head around PBKDF2 and AES. As a disclaimer, this is not going to be used in an actual application, I'm just testing things locally as a fun side project.
Right now what I'm trying to do is accept a password from someone to encrypt a message, and decrypt it at a later time.
I was doing the following:
key = InputPassword()
salt = RandomSalt()
self.key = PBKDF2(key, salt, 16)
I would then encrypt with AES. At the later time point, I would run:
key = InputPassword()
salt = RandomSalt()
self.key = PBKDF2(key, salt, 16)
again. Of course, my salt is going to be different each time. The problem seems to be that when the salt is different, AES decryption does not work. Am I therefore supposed to include the salt in the encrypted message? For example send something like: "message = message, salt=salt"? If so, what is the purpose of the salt, and what security benefit does including it confer?