Example of Php Encryption and Decryption
Here is a full working example of the above method in action. Feel free to use this, but make sure that you use a different key.
$key = 'qkwjdiw239&&jdafweihbrhnan&^%$ggdnawhd4njshjwuuO'; function encryptthis($data, $key) { $encryption_key = base64_decode($key); $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc')); $encrypted = openssl_encrypt($data, 'aes-256-cbc', $encryption_key, 0, $iv); return base64_encode($encrypted . '::' . $iv); } function decryptthis($data, $key) { $encryption_key = base64_decode($key); list($encrypted_data, $iv) = array_pad(explode('::', base64_decode($data), 2),2,null); return openssl_decrypt($encrypted_data, 'aes-256-cbc', $encryption_key, 0, $iv); } if(isset($_POST['submit'])){ $data=$_POST['foo']; $encrypted=encryptthis($data, $key); $decrypted=decryptthis($encrypted, $key); echo '<h2>Original Data</h2>'; echo '<p>'.$data.'</p>'; echo '<h2>Encrypted Data</h2>'; echo '<pre>'.$encrypted.'</pre>'; echo '<h2>Decrypted Data</h2>'; echo '<p>'.$decrypted.'</p>'; } echo '<form method="post"> <input type="text" name="foo"> <input type="submit" name="submit" value="submit"> </form>';
Data Encryption Php MySql Methods Implementation Open SSL Encrypt was last modified: April 29th, 2023 by
4 Comments
Want more info? Contact me.
Impressive sharing. For the base64 decode, here is the tool, I want to suggest
https://url-decode.com/tool/base64-decode
that tool not only provides base64 decode/encode, but you also get access to 100+ web utilities. That will definitely help, and the reader out, in their future projects.
Shame i cant find the code you show on your video =(
Sorry about that Brad, let me see if I can find it for you!