问题
maybe someone know how do this on PHP
echo "TEST" | openssl enc -e -aes-256-cbc -k 123456 -a -md md5
i will try like
$iv = openssl_random_pseudo_bytes(16); $data = base64_encode(openssl_encrypt('TEST', 'aes-256-cbc', $password, OPENSSL_RAW_DATA, $iv));
but not success..
回答1:
Interestingly, like the version at https://linux.die.net/man/1/enc , the man page for my local openssl installation lists '-md' (without an argument) as an option for openssl enc - but doesn't seem to explain what its for. The openssl wiki says its used for key derivation.
A bit more digging and I found this on the SO cryptography site.
But before attempting to write an implementation, since openssl's implementation is somewhat esoteric, it rather begs the question of whether there is a need to specifically support this in your implementation? If you merely need a method of encrypting/decrypting data outside your website, you could just write a command line PHP script.
A quick read through the linked document, suggests that....
$data = base64_encode(openssl_encrypt('TEST', 'aes-256-cbc', md5($password, true), OPENSSL_RAW_DATA, $iv));
But I expect that openssl is doing something else to the key in the derivation function to pad the 16 bytes out to the required 128 bits (why are you forcing a 128 bit key for a 256 bit algorithm?)
来源:https://stackoverflow.com/questions/49225904/openssl-encrypt-aes256