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


 

 

 

 

 

 

 

 

Decrypt MIME with PFX

Demonstrates how to decrypt MIME using a PFX (containing a digital certificate with private key). The content-type of an encrypted MIME message looks like this:

Content-Type: application/x-pkcs7-mime;
	name="smime.p7m"

<?php

$mime = new COM("Chilkat.Mime");

$success = $mime->UnlockComponent('Anything for 30-day trial');
if ($success == false) {
    print 'Failed to unlock component' . "\n";
    exit;
}

$success = $mime->LoadMimeFile('encryptedEmail.eml');
if ($success != true) {
    print $mime->lastErrorText() . "\n";
    exit;
}

$certStore = new COM("Chilkat.CertStore");
$success = $certStore->LoadPfxFile('myPfx.pfx','myPfxPassword');
if ($success != true) {
    print $certStore->lastErrorText() . "\n";
    exit;
}

//  Find the certificate by email address.  There are many
//  ways to find certificates within a Chilkat certificate store
//  object...

// cert is a Chilkat.Cert
$cert = $certStore->FindCertBySubjectE('support@chilkatsoft.com');
if (is_null($cert)) {
    print $certStore->lastErrorText() . "\n";
    exit;
}

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

    exit;
}

$success = $mime->Decrypt2($cert,$privKey);
if ($success != true) {
    print $mime->lastErrorText() . "\n";
    exit;
}

//  Show the decrypted MIME:
print $mime->getMime() . "\n";


?>

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

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