Delphi ActiveX Requires Chilkat v11.8.0+
Delphi ActiveX
Decrypt S/MIME using Added Credential Sources
See more MIME Examples
Loads a CMS/PKCS #7 encrypted S/MIME message and decrypts it back to the original MIME content.
The recipient's certificate and private key are supplied from a PEM file whose contents are added with AddPemSource, and Decrypt automatically selects the matching private key based on the CMS recipient information.
The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.
Background. Decrypt requires access to the recipient's private key. Chilkat matches the encrypted message's recipient identifiers against the certificates and keys made available through sources such as AddPemSource or AddDecryptCert.
Chilkat Delphi ActiveX Downloads
var
success: Integer;
mime: TChilkatMime;
pemPassword: WideString;
pem: TChilkatPem;
body: WideString;
begin
success := 0;
mime := TChilkatMime.Create(Self);
success := mime.LoadMimeFile('qa_data/encrypted.eml');
if (success = 0) then
begin
Memo1.Lines.Add(mime.LastErrorText);
Exit;
end;
// Load the recipient's certificate and private key (from a PEM file) so decryption can find them. The
// password of the private key should come from a secure source rather than being hard-coded.
pemPassword := 'myPemPassword';
pem := TChilkatPem.Create(Self);
success := pem.LoadPemFile('qa_data/recipient.pem',pemPassword);
if (success = 0) then
begin
Memo1.Lines.Add(pem.LastErrorText);
Exit;
end;
success := mime.AddPemSource(pem.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(mime.LastErrorText);
Exit;
end;
// Decrypt. Chilkat identifies the correct recipient from the CMS recipient info and uses the
// matching private key from the added sources.
success := mime.Decrypt();
if (success = 0) then
begin
Memo1.Lines.Add(mime.LastErrorText);
Exit;
end;
body := mime.GetBodyDecoded();
if (mime.LastMethodSuccess = 0) then
begin
Memo1.Lines.Add(mime.LastErrorText);
Exit;
end;
Memo1.Lines.Add(body);