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

 

 

 

 

 

 

 

Encrypt File to .p7m

Perl example program to encrypt a file to produce a .p7m as output. A digital certificate (public-key) is used for encrypting.

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

use chilkat();


$crypt = new chilkat::CkCrypt2();

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

#  Use public-key encryption with a digital certificate:
$crypt->put_CryptAlgorithm("pki");

#  There are many ways to select and load a digital certificate.
#  Certs can be retrieved from the Windows registry-based
#  certificate stores, from database tables, files, etc.
#  This example will load a .cer file.
$cert = new chilkat::CkCert();

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

$crypt->SetEncryptCert($cert);

#  The CkEncryptFile can encrypt files of any size.  The
#  encryption occurs in streaming mode, so it is not necessary
#  to hold the entire contents of the file in memory at once.
$success = $crypt->CkEncryptFile("dude.gif","dude.p7m");
if ($success != 1) {
    print $crypt->lastErrorText() . "\n";
    exit;
}

#  To decrypt the file, you'll need the private key.
#  Also, the certificate should have already been installed
#  on the computer.  This is typically achieved by installing
#  from a .pfx file, or by importing from a certificate
#  authority's online web application.  If you are decrypting
#  from ASP, ASP.NET, or a Windows Service, you'll need to
#  import in a way that provides the calling process permission
#  to access and use the private key.  The procedure for
#  doing this is explained here:
#  http://blog.chilkatsoft.com/?p=149
# 
#  Also, there is no "SetDecryptCert" method.  The .p7m
#  contains information that allows the Chilkat component
#  to locate the certificate to be used for decryption.
#  The Chilkat Crypt component automatically searches
#  the Windows Current User certificate store and the
#  Local Machine certificate store.
$success = $crypt->CkDecryptFile("dude.p7m","dudeOut.gif");
if ($success != 1) {
    print $crypt->lastErrorText() . "\n";
    exit;
}


 

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