Skip to content

Instantly share code, notes, and snippets.

@alpenzoo
Created June 6, 2019 14:55
Show Gist options
  • Save alpenzoo/7e2ceb12bbc60a72136bac55714e5113 to your computer and use it in GitHub Desktop.
Save alpenzoo/7e2ceb12bbc60a72136bac55714e5113 to your computer and use it in GitHub Desktop.
<?php
/** Encryption setup CODE **/
$key = openssl_pkey_new(array('private_key_bits' => 2048));
$private_key = openssl_pkey_get_details($key);
$public_key = $private_key['key'];
echo "<pre>";
print_r($private_key);
echo "</pre>";
/** Encryption CODE **/
$msg = "Hi, im sending you a private message";
openssl_public_encrypt($msg, $pvt_msg, $public_key);
echo "<pre>";
print_r($msg);
print_r($pvt_msg);
echo "</pre>";
/** Decryption CODE **/
openssl_private_decrypt( $pvt_msg, $received_msg, $key);
print $received_msg;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment