Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
Decrypt P7M using PFX to get MIMEDemonstrates how to decrypt a .p7m (PKCS7) binary file using a certificate and private key from a PFX file. The result of the decryption (in this case) is MIME text that may be loaded into a Chilkat MIME object. Note: Any type of file or data may be encrypted to produce a .p7m (PKCS7) encrypted file. This example was prompted by a customer needing to decrypt a MIME message. The final step of loading the decrypted text into a MIME object would be skipped if decrypting something other than MIME..
LOCAL loCrypt LOCAL lnSuccess LOCAL loP7mData LOCAL lcPfxFilePath LOCAL lcPfxPassword LOCAL lcMimeText LOCAL loMime loCrypt = CreateObject('Chilkat.Crypt2') * Any string argument automatically begins the 30-day trial. lnSuccess = loCrypt.UnlockComponent("30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCrypt.LastErrorText) QUIT ENDIF * Read the P7M file into memory. loP7mData = loCrypt.ReadFile("encrypted.p7m") * Setup the crypt object: * Indicate that public-key decryption is to be used. loCrypt.CryptAlgorithm = "pki" * Add a PFX file to allow the crypt object to find * the certificate and private key needed for decryption lcPfxFilePath = "myPfx.pfx" lcPfxPassword = "secret" lnSuccess = loCrypt.AddPfxSourceFile(lcPfxFilePath,lcPfxPassword) IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCrypt.LastErrorText) QUIT ENDIF * Assuming the decrypted data will be text, decrypt to * a string. lcMimeText = loCrypt.DecryptString(loP7mData) IF (lcMimeText = NULL ) THEN =MESSAGEBOX(loCrypt.LastErrorText) QUIT ENDIF * Note: Chilkat Crypt and Chilkat MIME are separate products. * To use both objects, one would license the "Chilkat Bundle", * which provides licenses to all existing Chilkat products. * This is less expensive than licensing each of the two products separately. loMime = CreateObject('Chilkat.Mime') lnSuccess = loMime.UnlockComponent("Anyting for 30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loMime.LastErrorText) QUIT ENDIF * Load the MIME text into the MIME object. lnSuccess = loMime.LoadMime(lcMimeText) IF (lnSuccess <> 1) THEN =MESSAGEBOX(loMime.LastErrorText) QUIT ENDIF * Save the MIME to a file: lnSuccess = loMime.SaveMime("outMime.txt") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loMime.LastErrorText) QUIT ENDIF * Success! Output the MIME text: ? loMime.GetMime() |
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser