Quantcast
Channel: Chilkat Forum - latest questions
Viewing all articles
Browse latest Browse all 1061

How to load rsa keys from pem file and encrypt/decrypt string

$
0
0

Hello, I am unsure how to correctly load a pem file I generate and saved to disk. I want to load the public key, encode a string and load the private key from another pem file to decrypt the string. I did try with LoadPem as no Password is given, but can not get it to work.

I am currently generating and writing the pem files as follows (works very well):

<?php
include("chilkat_9_5_0.php");

$rsa = new CkRsa();

$success = $rsa->UnlockComponent("using my key");
if ($success != true) {
    print 'RSA unlock failed' . "\n";
    exit;
}
$success = $rsa->GenerateKey(2048);
if ($success != true) {
    print $rsa->lastErrorText() . "\n";
    exit;
}

$publicKeyXml = $rsa->exportPublicKey();
print "public: ".$publicKeyXml . "\n";

$privateKeyXml = $rsa->exportPrivateKey();
print "private: ".$privateKeyXml . "\n";

//  Save the private key in PEM format:
$privKey = new CkPrivateKey();
$success = $privKey->LoadXml($privateKeyXml);
$success = $privKey->SaveRsaPemFile('privateKey.pem');

//  Save in PEM format
$pubKey = new CkPublicKey();
$success = $pubKey->LoadXml($publicKeyXml);
$success = $pubKey->SaveOpenSslPemFile('publicKey.pem');

?>

Viewing all articles
Browse latest Browse all 1061

Trending Articles