The password
123
will be encrypted and then decrypted back with
AES-128-ECB
encryption algorithm. Encrypts the text using the secret key
sec key
function encrypt_text($text, $secret_key)
{
    return openssl_encrypt($text,"AES-128-ECB", $secret_key);
}
Decrypts encrypted text (first parameter) using the secret key (second parameter)
function decrypt_text($encrypted_string, $secret_key)
{
    return openssl_decrypt($encrypted_string,"AES-128-ECB", $secret_key);
}
Calls the above two functions to perform encryption and decryption
// Secret key, that is used to encrypt and decrypt the 
$text
content $secret = 'sec key'; // the text that we want to encryption and decryption $text = '123'; $password_encrypted = encrypt_text($text, $secret); $password_decrypted = decrypt_text($password_encrypted, $secret); echo 'Encrypted text: ' . $password_encrypted . '<br>'; echo 'Decrypted password: ' . $password_decrypted;
by Valeri Tandilashvili
4 years ago
PHP
encrypt/decrypt
1
Pro tip: use ```triple backticks around text``` to write in code fences