Skip to content

Instantly share code, notes, and snippets.

@joshapgar
Created August 7, 2017 15:49
Show Gist options
  • Save joshapgar/ae9b0e32d56cd69c992fd6bc6f989d02 to your computer and use it in GitHub Desktop.
Save joshapgar/ae9b0e32d56cd69c992fd6bc6f989d02 to your computer and use it in GitHub Desktop.
Encrypt and Decrypt Data
//Encryption:
$textToEncrypt = "My Text to Encrypt";
$encryptionMethod = "AES-256-CBC";
$secretHash = "encryptionhash";
$iv = mcrypt_create_iv(16, MCRYPT_RAND);
$encryptedText = openssl_encrypt($textToEncrypt,$encryptionMethod,$secretHash, 0, $iv);
//Decryption:
$decryptedText = openssl_decrypt($encryptedText, $encryptionMethod, $secretHash, 0, $iv);
print "My Decrypted Text: ". $decryptedText;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment