echo "Lorem ipsum" | openssl enc -aes-256-cbc -pbkdf2 -iter 100000 -out message.enc -pass file:shared_key.binwill take the input string from
echo to openssl. It then will1. use the content of
shared_key.bin as password2. use
PBKDF2 with an iteration of 100000 to generate a encryption key from the given password (shared_key.bin)3. use the
PBKDF2 generated key for an aes-256-cbc encryptionThe final result is encrypted data with the prepended salt (which was generated by runtime), e.g.:
Salted__q�;��-�T���"h%��5�� ....With a dummy script I now can generate a valide shared key within PHP 'openssl_pkey_derive()' - identical to OpenSSL.
I also can en-/decrypt salted data within my script, but not with OpenSSL. There are several parameters of
PBKDF2 unknown to me.Question:
1. Is the salt, used by
aes-256-cbc and PBKDF2 the same, prepended in the encrypted data?2. Witch algorithm/cipher is used within
PBKDF2: sha1, sha256, ...?3. What is the desired key length of
PBKDF2 (https://www.php.net/manual/en/function.openssl-pbkdf2.php)?To be continued ...