openssl_encrypt()
and openssl_decrypt()
functions can be used to encrypt and decrypt text in PHP.openssl_encrypt()
and openssl_decrypt()
functions.
<?php $password = 'user_pass'; //password added by user $_POST['password'] $key_enc = '1234'; //key for encrypt $met_enc = 'aes256'; //method to encrypt: aes128, aes192, aes256, blowfish, cast-cbc $iv = '16_characters_ok'; //a random string with 16 characters //encrypts the password $pass_enc = openssl_encrypt($password, $met_enc, $key_enc, 0, $iv); echo $pass_enc; // "uw4QKRUsG+l17w5epb7nKw==" //decrypts the encrypted password, it uses the same arguments: $met_enc, $key_enc, $opt=0, $iv $pass_enc ='uw4QKRUsG+l17w5epb7nKw=='; //the encrypted password $pass = openssl_decrypt($pass_enc, $met_enc, $key_enc, 0, $iv); echo '<br>'.$pass; // "user_pass" ?>
Notice, the openssl_decrypt() must use the same arguments (here: $met_enc, $key_enc, $opt=0, $iv) to decrypt the string encrypted with openssl_encrypt().
<input type="text" name="a_name" value="val" />
h3 { font-variant: small-caps; }
var msg = "Visit CoursesWeb.net"; alert(msg);
$ip = $_SERVER["REMOTE_ADDR"]; echo $ip;