PHP Requires Chilkat v11.0.0+
PHP
RSA Sign using Base64 Private Key
See more RSA Examples
Signs a string using a non-encrypted RSA private key in base64 encoding. Returns the RSA signature as a base64 string.Chilkat PHP Downloads
<?php
use Chilkat2\BinData;
use Chilkat2\PrivateKey;
use Chilkat2\Rsa;
use Chilkat2\StringBuilder;
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$privKey = new PrivateKey();
$sbPem = new StringBuilder();
$sbPem->AppendLine('-----BEGIN RSA PRIVATE KEY-----', true);
$sbPem->AppendLine('MIIC .... j5A==', true);
$sbPem->AppendLine('-----END RSA PRIVATE KEY-----', true);
try {
$privKey->LoadPem($sbPem->GetAsString());
$rsa = new Rsa();
$rsa->UsePrivateKey($privKey);
$bd = new BinData();
$bd->AppendString('12345678', 'utf-8');
$rsa->SignRawBd($bd);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
// Get the base64 RSA signature.
echo $bd->GetEncoded('base64'), "\n";
try {
$rsa->VerifyRawBd($bd);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
$strOriginal = $bd->GetString('utf-8');
echo $strOriginal, "\n";