Programming Examples

ChilkatHOMEASPVisual BasicVB.NETC#CC++MFCDelphiFoxProJavaPerlPythonRubySQL ServerVBScript

PHP ActiveX Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
DKIM / DomainKey
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
MIME
NTLM
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip
Amazon S3


 

 

 

 

 

 

 

 

RSA Signature with Certificate's Private Key from PFX

Demonstrates how to use a certificate's private key from a PFX file to create an RSA signature.

Download 32-bit Chilkat RSA ActiveX (.msi)

Download All 32-bit Chilkat ActiveX Components (.zip)

Download All 64-bit Chilkat ActiveX Components (.zip)

<?php



//  Create an instance of a certificate store object, load a PFX file,
//  locate the certificate we need, and use it for signing.
//  (a PFX file may contain more than one certificate.)
$certStore = new COM("Chilkat.CertStore");

//  The 1st argument is the filename, the 2nd arg is the
//  PFX file's password:
$success = $certStore->LoadPfxFile('chilkat.pfx','test');
if ($success != true) {
    print $certStore->lastErrorText() . "\n";
    exit;
}

// cert is a Chilkat.Cert
$cert = $certStore->FindCertBySubject('Chilkat Software, Inc.');
if (is_null($cert)) {
    print $certStore->lastErrorText() . "\n";
    exit;
}

// pkey is a Chilkat.PrivateKey
$pkey = $cert->ExportPrivateKey();
if (is_null($pkey)) {
    print $cert->lastErrorText() . "\n";
    exit;
}

//  Get the private key in XML format:
$pkeyXml = $pkey->getXml();

$rsa = new COM("Chilkat.Rsa");

//  Any string argument automatically begins the 30-day trial.
$success = $rsa->UnlockComponent('30-day trial');
if ($success != true) {
    print 'RSA component unlock failed' . "\n";
    exit;
}

//  Import the private key into the RSA component:
$success = $rsa->ImportPrivateKey($pkeyXml);
if ($success != true) {
    print $rsa->lastErrorText() . "\n";
    exit;
}

//  This example will sign a string, and receive the signature
//  in a hex-encoded string.  Therefore, set the encoding mode
//  to "hex":
$rsa->EncodingMode = 'hex';

//  If some other non-Chilkat application or web service is going to be verifying
//  the signature, it is important to match the byte-ordering.
//  The LittleEndian property may be set to 1
//  for little-endian byte ordering,
//  or 0  for big-endian byte ordering.
//  Microsoft apps typically use little-endian, while
//  OpenSSL and other services (such as Amazon CloudFront)
//  use big-endian.
$rsa->LittleEndian = false;

$strData = 'This is the string to be signed.';

//  Sign the string using the sha-1 hash algorithm.
//  Other valid choices are "md2" and "md5".
$hexSig = $rsa->signStringENC($strData,'sha-1');

print $hexSig . "\n";

print 'Success!' . "\n";
?>

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.