Sample code for 30+ languages & platforms
Perl 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 Perl Downloads

Perl
use strict;
use warnings;
use Chilkat2;

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

my $pubkey = Chilkat2::PublicKey->new;

my $success = $pubkey->LoadBase64('MIICdgIBADA ... A9PXLk+j5A==');
if (!$success) {
    print $pubkey->LastErrorText, "\n";
    exit;
}

my $rsa = Chilkat2::Rsa->new;

$success = $rsa->UsePublicKey($pubkey);
if (!$success) {
    print $rsa->LastErrorText, "\n";
    exit;
}

$rsa->EncodingMode('base64');

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

print $encryptedStr, "\n";