I have created 2 scripts to encrypt and decrypt a password inside a file.

The encryption script is as follow:

set -x
echo "changing PASSWORD"
P=`echo 'rawpassword' | openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 1000 -salt -pass pass:'secret'`
sed -i "/PASSWORD=/ s|=.*|=${P}|" $PFILE

And the decrypt password is:


PASSWORD=$(sed -n 's|^PASSWORD=||p' $PFILE)
pass=`echo $PASSWORD | openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 1000 -d -salt -pass pass:'secret'`

echo $pass

This decryption script shows the raw password successfully, but still gives me this error:

bad decrypt
140392493330880:error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length:../crypto/evp/evp_enc.c:526:

Does anyone knows what is causing this error? Since he is decrypting successfully, I'm not sure what's missing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.