Sample code for 30+ languages & platforms
PHP ActiveX

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 PHP ActiveX Downloads

PHP ActiveX
<?php

$success = 0;

$cert = new COM("Chilkat.Cert");

$success = $cert->LoadFromFile('qa_data/pem/mf_public_rsa.pem');
if ($success == 0) {
    print $cert->LastErrorText . "\n";
    exit;
}

$pubKey = new COM("Chilkat.PublicKey");
$cert->GetPublicKey($pubKey);

$rsa = new COM("Chilkat.Rsa");
$rsa->UsePublicKey($pubKey);

$rsa->EncodingMode = 'base64';
$encryptedStr = $rsa->encryptStringENC('hello',0);
print 'encrypted string = ' . $encryptedStr . "\n";

?>