Perl Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

Perl Examples

Quick Start
Unicode
Byte Array
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML Conversion
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
Signatures
SMTP
Socket / SSL
Spider
SFTP
SSH Key
SSH
SSH Tunnel
Tar
HTTP Upload
XML
XMP
Zip

More Examples...
String
Amazon S3
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

 

Create PKCS7 Signature using .cer and .key Files

Uses a digital certificate (.cer file) and private key file to create a PKCS7 signature.

 Chilkat Perl Module Downloads for Windows, Linux, and MAC OS X

use chilkat();

#  First, load the .cer and .key files into Chilkat objects...
$cert = new chilkat::CkCert();

$success = $cert->LoadFromFile("myCert.cer");
if ($success != 1) {
    print $cert->lastErrorText() . "\r\n";
    exit;
}

$privKey = new chilkat::CkPrivateKey();
$password = "myPassword";
#  The private key object provides different methods for
#  loading keys of many different formats.
#  This example loads a PKCS8 encrypted private key.
$success = $privKey->LoadPkcs8EncryptedFile("myPrivateKey.key",$password);
if ($success != 1) {
    print $privKey->lastErrorText() . "\r\n";
    exit;
}

#  NOTE:  In this example, the .cer should contain the public key
#  that corresponds to the private key.

$crypt = new chilkat::CkCrypt2();

#  Any string argument automatically begins the 30-day trial.
$success = $crypt->UnlockComponent("30-day trial");
if ($success != 1) {
    print $crypt->lastErrorText() . "\r\n";
    exit;
}

#  Set the certifcate + private key to be used for signing:
$crypt->SetSigningCert2($cert,$privKey);

$pkcs7 = new chilkat::CkByteData();

$textToSign = "This is the text to be signed.";
$success = $crypt->SignString($textToSign,$pkcs7);
if ($success == 0) {
    print $crypt->lastErrorText() . "\r\n";
    exit;
}

#  Save the PKCS7 signature to a file.
$success = $pkcs7->saveFile("out_pkcs7.p7s");
if ($success == 0) {
    print "Failed to save output file." . "\n";
}
else {
    print "Success." . "\n";
}

 

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