Answers for "openssl_encrypt doc php"

5

openssl_encrypt

$textToEncrypt = "My super secret information.";
$encryptionMethod = "AES-256-CBC";  // AES is used by the U.S. gov't to encrypt top secret documents.
$secretHash = "25c6c7ff35b9979b151f2136cd13b0ff";

//To encrypt
$encryptedMessage = openssl_encrypt($textToEncrypt, $encryptionMethod, $secretHash);

//To Decrypt
$decryptedMessage = openssl_decrypt($encryptedMessage, $encryptionMethod, $secretHash);

//Result
echo "Encrypted: $encryptedMessage <br>Decrypted: $decryptedMessage";
Posted by: Guest on August-06-2020
1

openssl encrypt php

function rw_hash($string, $encrypt = true)
	{
		$encrypt_method = "AES-256-CBC";
		$secret_key = "AA74CDCC2BBRT935136HH7B63C27"; // user define private key
		$secret_iv = "RwS3cr3t"; // user define secret key
		$key = hash("sha256", $secret_key);
		$iv = substr(hash("sha256", $secret_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;
	}
Posted by: Guest on August-04-2021

Browse Popular Code Answers by Language