Sample code for 30+ languages & platforms
PHP Extension

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

PHP Extension
<?php

include("chilkat.php");

$success = false;

$cert = new CkCert();

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

$pubKey = new CkPublicKey();
$cert->GetPublicKey($pubKey);

$rsa = new CkRsa();
$rsa->UsePublicKey($pubKey);

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

?>