Skip to content

Instantly share code, notes, and snippets.

@MarQuisKnox
Forked from glynrob/gist:7059838
Last active August 29, 2015 14:20
Show Gist options
  • Save MarQuisKnox/4f0c89fa0e43e83c2e23 to your computer and use it in GitHub Desktop.
Save MarQuisKnox/4f0c89fa0e43e83c2e23 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