Skip to content

Instantly share code, notes, and snippets.

@SecureCloud-biz
Forked from glynrob/gist:7059838
Last active August 29, 2015 14:13
Show Gist options
  • Save SecureCloud-biz/0d9dfa9220cfb2b35ed4 to your computer and use it in GitHub Desktop.
Save SecureCloud-biz/0d9dfa9220cfb2b35ed4 to your computer and use it in GitHub Desktop.
ENCRYPT / DECRYPT PHP Functions
<?php
// https://glynrob.com/php/hashing-and-public-key-encryption/
function public_encrypt($plaintext){
$fp=fopen("./mykey.pub","r");
$pub_key=fread($fp,8192);
fclose($fp);
openssl_get_publickey($pub_key);
openssl_public_encrypt($plaintext,$crypttext, $pub_key );
return(base64_encode($crypttext));
}
function private_decrypt($encryptedext){
$fp=fopen("./mykey.pem","r");
$priv_key=fread($fp,8192);
fclose($fp);
$private_key = openssl_get_privatekey($priv_key);
openssl_private_decrypt(base64_decode($encryptedext), $decrypted, $private_key);
return $decrypted;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment