Why is AES encrypted cipher of the same string with the same key always different?

后端 未结 4 1202
我寻月下人不归
我寻月下人不归 2021-01-21 14:21

I have a file called plain.txt. Inside the file I have:

Hello Hello Hello Hello

I am using this command to encrypt it:

openssl          


        
4条回答
  •  独厮守ぢ
    2021-01-21 14:38

    The reason is that the actual key which is used for encryption is driven from your passphrase and the SALT. Then definitely the ciphertext will be different even if you still use the same password because the SALT is different.

    Openssl uses salt by default to mitigate dictionary attacks. If you don't want to use it then use same salt as suggested by other answers, or add nosalt option as follow:

    openssl enc -aes-128-cbc -nosalt -k "Hello" -in plain.txt -out encrypted.bin
    

    You can see the ciphertext in hex using xxd

    xxd encrypted.bin
    

提交回复
热议问题