Php-mysql Course

The openssl_encrypt() and openssl_decrypt() functions can be used to encrypt and decrypt text in PHP.
They are useful to encrypt and decrypt the user password in a register /login script.

- Here is a simple example with the openssl_encrypt() and openssl_decrypt() functions.
$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().

Daily Test with Code Example

Which tag create a highlighted bolded text?
<q> <strong> <em>
<p>Address: <strong></strong> - Tutorials.</p>
Which of these CSS codes displays the text bolded?
text-size: 18px; font-style: italic; font-weight: 800;
#id {
  font-weight: 800;
What JavaScript function can be used to call another function multiple times, to a specified time interval?
setInterval() setTimeout() push()
function someFunction() { alert(""); }
setInterval("someFunction()", 2000);
Click on the correctly defined variable in PHP.
var vname = 8; $vname = 8; $vname == 8;
$vname = 8;
echo $vname;
Using openssl_encrypt and openssl_decrypt in PHP

Last accessed pages

  1. Get data from string with JSON object (2268)
  2. Calling Function and Class Method with Name from String (2503)
  3. PHP Unzipper - Extract Zip, Rar Archives (11898)
  4. Select in MySQL, Output results in HTML Table (15821)
  5. querySelector and querySelectorAll (21490)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (688)
  2. SHA256 Encrypt hash in JavaScript (645)
  3. Read Excel file data in PHP - PhpExcelReader (616)
  4. PHP Unzipper - Extract Zip, Rar Archives (596)
  5. Create simple Website with PHP (595)