Skip to content

Instantly share code, notes, and snippets.

@glynrob
Created October 19, 2013 18:46
Show Gist options
  • Save glynrob/7059838 to your computer and use it in GitHub Desktop.
Save glynrob/7059838 to your computer and use it in GitHub Desktop.
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