Perl Requires Chilkat v11.0.0+
Perl
RSA Import Public Key from Certificate PEM
See more RSA Examples
Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.Chilkat Perl Downloads
use strict;
use warnings;
use Chilkat2;
my $cert = Chilkat2::Cert->new;
my $success = $cert->LoadFromFile('qa_data/pem/mf_public_rsa.pem');
if (!$success) {
print $cert->LastErrorText, "\n";
exit;
}
my $pubKey = Chilkat2::PublicKey->new;
$cert->GetPublicKey($pubKey);
my $rsa = Chilkat2::Rsa->new;
$rsa->UsePublicKey($pubKey);
$rsa->EncodingMode('base64');
my $encryptedStr = $rsa->EncryptStringENC('hello', 0);
print 'encrypted string = ', $encryptedStr, "\n";