Delphi DLL
Delphi DLL
Extract PKCS7 from MIME and Decrypt
See more MIME Examples
Extracts the base64-encoded PKCS7 body of a MIME message to a file, and then decrypts using Chilkat Crypt2.Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Crypt2, Mime;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
mime: HCkMime;
crypt: HCkCrypt2;
inPath: PWideChar;
outPath: PWideChar;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
mime := CkMime_Create();
success := CkMime_LoadMimeFile(mime,'c:/aaworkarea/EmailInBytes.txt');
if (success <> True) then
begin
Memo1.Lines.Add(CkMime__lastErrorText(mime));
Exit;
end;
success := CkMime_SaveBody(mime,'c:/aaworkarea/smime.p7m');
if (success <> True) then
begin
Memo1.Lines.Add(CkMime__lastErrorText(mime));
Exit;
end;
crypt := CkCrypt2_Create();
success := CkCrypt2_AddPfxSourceFile(crypt,'c:/aaworkarea/my.pfx','pfxPassword');
if (success = False) then
begin
Memo1.Lines.Add(CkCrypt2__lastErrorText(crypt));
Exit;
end;
// Indicate the public-key (PKCS7) encryption/decryption should be used:
CkCrypt2_putCryptAlgorithm(crypt,'pki');
inPath := 'c:/aaworkarea/smime.p7m';
outPath := 'c:/aaworkarea/decrypted.dat';
success := CkCrypt2_CkDecryptFile(crypt,inPath,outPath);
if (success = False) then
begin
Memo1.Lines.Add(CkCrypt2__lastErrorText(crypt));
Exit;
end;
Memo1.Lines.Add('Success.');
CkMime_Dispose(mime);
CkCrypt2_Dispose(crypt);
end;