note 124245 deleted from function.openssl-encrypt by cmb

From: Date: Sun, 29 Sep 2019 10:31:08 +0000
Subject: note 124245 deleted from function.openssl-encrypt by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212431@lists.php.net to get a copy of this message
Note Submitter: handsomedmm at 126 dot com ---- if encrypt data by openssl enc command with pass and salt, it can aslo decrypt by openssl_decrypt. eg. encrypt command: # echo -n test123 | openssl enc -aes-128-cbc -pass pass:"pass123" -a -md md5 decrypt command: # echo -n U2FsdGVkX19349P4LpeP5Sbi4lpCx6lLwFQ2t9xs2AQ= | base64 -d| openssl enc -aes-128-cbc -pass pass:"pass123" -md md5 -d -p salt=77E3D3F82E978FE5 key=9CA70521F78B9909BF73BAE9233D6258 iv =04BCCB509EC9E6F5AF7E822CA58EA557 test123 use php code <?php // encode data $encodeData = "U2FsdGVkX19349P4LpeP5Sbi4lpCx6lLwFQ2t9xs2AQ="; // base64 decode $data = base64_decode($encodeData); $data = substr($data, 16); // if salted , remove Salted__ prefix // salt and pass config $salt = hex2bin("77E3D3F82E978FE5"); $pass = "pass123"; $method = "AES-128-CBC"; // generate iv and key $hash1 = md5($pass . $salt); $hash2 = md5(hex2bin($hash1) . $pass . $salt); $key = hex2bin($hash1); $iv = hex2bin($hash2); $decodeData = openssl_decrypt($data, $method, $key, OPENSSL_RAW_DATA, $iv); var_dump($decodeData);

« previous php.notes (#212431) next »