Sample code for 30+ languages & platforms
Perl

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 Perl Downloads

Perl
use chilkat();

$success = 0;

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

$pubkey = chilkat::CkPublicKey->new();

$success = $pubkey->LoadBase64("MIICdgIBADA ... A9PXLk+j5A==");
if ($success == 0) {
    print $pubkey->lastErrorText() . "\r\n";
    exit;
}

$rsa = chilkat::CkRsa->new();

$success = $rsa->UsePublicKey($pubkey);
if ($success == 0) {
    print $rsa->lastErrorText() . "\r\n";
    exit;
}

$rsa->put_EncodingMode("base64");

$encryptedStr = $rsa->encryptStringENC("12345678",0);

print $encryptedStr . "\r\n";