1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<?php function encrypt_decrypt($action, $string) { $output = false; $encrypt_method = "AES-128-ECB"; $key = 'This is my secre'; if ( $action == 'encrypt' ) { $output = openssl_encrypt($string, $encrypt_method, $key); $output; } else if( $action == 'decrypt' ) { $output = openssl_decrypt($string, $encrypt_method, $key); } return $output; } $plain_txt = "This is my plain text"; echo "Plain Text =" .$plain_txt. "\n"; $encrypted_txt = encrypt_decrypt('encrypt', $plain_txt); echo "Encrypted Text = " .$encrypted_txt. "\n"; $decrypted_txt = encrypt_decrypt('decrypt', $encrypted_txt); echo "Decrypted Text =" .$decrypted_txt. "\n"; if ( $plain_txt === $decrypted_txt ) echo "SUCCESS"; else echo "FAILED"; echo "\n"; ?> |