Created
July 22, 2020 07:48
-
-
Save BhargavBhandari90/5d3cf99e1dd3d2e7c0c3a5e696c43d2f to your computer and use it in GitHub Desktop.
PHP OPENSSL ENCRIPTION DESCRIPTION
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Store a string into the variable which | |
// need to be Encrypted | |
$simple_string = "Welcome to GeeksforGeeks\n"; | |
// Display the original string | |
echo "Original String: " . $simple_string; | |
// Store the cipher method | |
$ciphering = "AES-128-CTR"; | |
// Use OpenSSl Encryption method | |
$iv_length = openssl_cipher_iv_length($ciphering); | |
$options = 0; | |
// Non-NULL Initialization Vector for encryption | |
$encryption_iv = '1234567891011121'; | |
// Store the encryption key | |
$encryption_key = "GeeksforGeeks"; | |
// Use openssl_encrypt() function to encrypt the data | |
$encryption = openssl_encrypt($simple_string, $ciphering, | |
$encryption_key, $options, $encryption_iv); | |
// Display the encrypted string | |
echo "Encrypted String: " . $encryption . "\n"; | |
// Non-NULL Initialization Vector for decryption | |
$decryption_iv = '1234567891011121'; | |
// Store the decryption key | |
$decryption_key = "GeeksforGeeks"; | |
// Use openssl_decrypt() function to decrypt the data | |
$decryption=openssl_decrypt ($encryption, $ciphering, | |
$decryption_key, $options, $decryption_iv); | |
// Display the decrypted string | |
echo "Decrypted String: " . $decryption; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment