Created
September 9, 2015 14:16
-
-
Save niraj-shah/060797d0eaecf98d9601 to your computer and use it in GitHub Desktop.
Public/Privacy Key Encryption and Decryption example using PHP
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 | |
$string = "I'm using PHP to encrypt and decrypt data!"; | |
$publicKey = file_get_contents( 'public.pub' ); | |
openssl_public_encrypt( $string, $encrypted, $publicKey ); | |
$encrypted = base64_encode( $encrypted ); | |
echo '<h1>Encrypted String</h1>'; | |
echo $encrypted; | |
$privKey = file_get_contents( 'private.key' ); | |
openssl_private_decrypt( base64_decode( $encrypted ), $decrypted, $privKey ); | |
echo '<h1>Decrypted String</h1>'; | |
echo $decrypted; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment