xxxxxxxxxx
$decoded = base64_decode($encoded);
xxxxxxxxxx
<?php
// Encryption function
function encrypt($data, $encryptionKey) {
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('AES-128-CBC'));
$encrypted = openssl_encrypt($data, 'AES-128-CBC', $encryptionKey, 0, $iv);
return base64_encode($iv . $encrypted);
}
// Decryption function
function decrypt($encryptedData, $encryptionKey) {
$encryptedData = base64_decode($encryptedData);
$ivLength = openssl_cipher_iv_length('AES-128-CBC');
$iv = substr($encryptedData, 0, $ivLength);
$encrypted = substr($encryptedData, $ivLength);
return openssl_decrypt($encrypted, 'AES-128-CBC', $encryptionKey, 0, $iv);
}
// Example usage
$data = "Hello, World!";
$encryptionKey = "mySecretKey";
$encrypted = encrypt($data, $encryptionKey);
echo "Encrypted data: " . $encrypted . "\n";
$decrypted = decrypt($encrypted, $encryptionKey);
echo "Decrypted data: " . $decrypted . "\n";
?>
xxxxxxxxxx
//Key
$key = 'SuperSecretKey';
//To Encrypt:
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, 'I want to encrypt this', MCRYPT_MODE_ECB);
//To Decrypt:
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $encrypted, MCRYPT_MODE_ECB);
xxxxxxxxxx
function _hash($string, $encrypt = true){
$key = "openSSL_key";
$iv = "openSSL_iv";
if ($key && $iv){
$encrypt_method = "AES-256-CBC";
$key = hash("sha256", $key);
$iv = substr(hash("sha256", $iv), 0, 16); // sha256 is hash_hmac_algo
if ($encrypt) {
$output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
$output = base64_encode($output);
} else {
$output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
}
return $output;
}
return false;
}
# encrypt
echo _hash('addin.my.id'); // VWZNcHhacmJvRmtuVHlMMEZTMUFNUT09
# decrypt
echo _hash('VWZNcHhacmJvRmtuVHlMMEZTMUFNUT09', false); // addin.my.id
xxxxxxxxxx
<?php
$encrypted_text = "qnHWqq1mElDqW2RCepH14VriPf5s2Q==";
$cipher = "AES-128-CTR";
$key = "Blog Desire";
$iv = "1232434565432123";
$original_text = openssl_decrypt ($encrypted_text, $cipher, $key, $options = 0, $iv);
echo $original_text;