Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //encrypt dcrypt sederhana
- //keisengan untuk keisengan
- //created by kakatoji
- function encrypt_decrypt($action, $string) {
- $output = false;
- $encrypt_method = "AES-256-CBC";
- $secret_key = 'key_one';
- $secret_iv = 'key_two';
- $key = hash('sha256', $secret_key);
- $iv = substr(hash('sha256', $secret_iv), 0, 16);
- if ( $action == 'encrypt' ) {
- $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
- $output = base64_encode($output);
- } else if( $action == 'decrypt' ) {
- $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
- }
- return $output;
- }
- // Contoh Penggunaan
- $plain_txt = "hai salam kenal saya kakatoji";
- $encrypted_txt = encrypt_decrypt('encrypt', $plain_txt);
- $decrypted_txt = encrypt_decrypt('decrypt', $encrypted_txt);
- echo $encrypted_txt;
Add Comment
Please, Sign In to add comment