encrypt file with openssl code example

Example 1: 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 
Decrypted: $decryptedMessage";

Example 2: use openssl to encrypt a file window

openssl enc -aes-256-cbc -salt -a -in solvetic.txt -out solvetic.txt.enc

Tags:

Misc Example