Encryption & Decryption

The following PHP encryption examples use the phpseclib secure communications library.

Encrypt Message

Encrypt message using RSA public key with PKCS1-OAEP padding:

<?
public function rsa_encrypt($key, $message) {
    $rsa = new Crypt_RSA();
    $rsa->loadKey($key);
    $encrypted = base64_encode($rsa->encrypt($message));
    return $encrypted;
}
?>

Decrypt Package

Decrypt a package using RSA private key with PKCS1-OAEP padding:

<?
public function rsa_decrypt($key, $package) {
    $rsa = new Crypt_RSA();
    $rsa->loadKey($key);
    $decrypted = $rsa->decrypt(base64_decode($package));
    return $decrypted;
}
?>

User Contributed

LaunchKey links to user contributed code as a resource to its community. LaunchKey does not in any way guarantee or warrant the quality and security of these code bases. User contributed code is supported by the creators. If you do find a link from the site to user contributed code that is malicious or inappropriate in any way, please report that link to LaunchKey immediately and we will investigate the claim. Submit any issue to LaunchKey support at https://launchkey.com./support. ×