aes php
function encrypt($plaintext, $password) {
$method = "AES-256-CBC";
$key = hash('sha256', $password, true);
$iv = openssl_random_pseudo_bytes(16);
$ciphertext = openssl_encrypt($plaintext, $method, $key, OPENSSL_RAW_DATA, $iv);
$hash = hash_hmac('sha256', $ciphertext . $iv, $key, true);
return $iv . $hash . $ciphertext;
}
function decrypt($ivHashCiphertext, $password) {
$method = "AES-256-CBC";
$iv = substr($ivHashCiphertext, 0, 16);
$hash = substr($ivHashCiphertext, 16, 32);
$ciphertext = substr($ivHashCiphertext, 48);
$key = hash('sha256', $password, true);
if (!hash_equals(hash_hmac('sha256', $ciphertext . $iv, $key, true), $hash)) return null;
return openssl_decrypt($ciphertext, $method, $key, OPENSSL_RAW_DATA, $iv);
}
//Example usage:
$encrypted = encrypt('Plaintext string.', 'password'); // this yields a binary string
echo decrypt($encrypted, 'password');
// decrypt($encrypted, 'wrong password') === null
Also in PHP:
- acf form update post
- file_get_contents(http://cnh.local/dsc/uploads/1359e1e4c0a10294d9894146beb3e1e9.crt): failed to open stream: HTTP request failed! HTTP/1.0 500 Internal Server Error in file /opt/gitco/cnh_laravel/app/Repositories/CallRepository.php
- composer in serveur ionos
- define php
- call a seeder in databaseseeder laravel
- codeigniter where_not_in
- enie letter validation laravel regex
- date conversion php
- can i back up mysql database from php code?
- convert text toupper case php
- check if key array exist php
- enfold remove debugging info for theme support
- check value present in string php
- curl_init() in php
- LARAVEL DISABLE LOGIN REGISTER ROUTEA
- file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:1416F086:SSL
- declare variable in view for loop laravel
- check if string contains only whitespace php
- $date- format php
- Wordpress login page Background Image / Logo Image
- What was the old name of PHP?
- array merge in php
- day date attributes php
- convert a php array into a javascript array