Sample code for 30+ languages & platforms
PHP Requires Chilkat v11.0.0+

Use Base64 RSA Key to Encrypt

See more RSA Examples

Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64.

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\PublicKey;
use Chilkat2\Rsa;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

$pubkey = new PublicKey();

try {
    $pubkey->LoadBase64('MIICdgIBADA ... A9PXLk+j5A==');

    $rsa = new Rsa();

    $rsa->UsePublicKey($pubkey);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

$rsa->EncodingMode = 'base64';

$encryptedStr = $rsa->EncryptStringENC('12345678', false);

echo $encryptedStr, "\n";