Delphi ActiveX Requires Chilkat v11.8.0+
Delphi ActiveX
Add a PEM File as a Decryption Source
See more MIME Examples
Loads a CMS/PKCS #7 encrypted S/MIME message and decrypts it back to the original MIME content.
AddPemSource registers the certificates and private keys of a Pem object, here loaded from a PEM file, as a source of certificates and private keys used by subsequent decryption operations.
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. Multiple PEM sources can be added so that a single Mime object is able to decrypt messages addressed to any of several identities. Chilkat chooses the matching key at decryption time.
AddPemSource was added in Chilkat v11.8.0 and replaces UseCertVault and the AddPfxSource methods.Chilkat Delphi ActiveX Downloads
var
success: Integer;
mime: TChilkatMime;
pemPassword: WideString;
pem: TChilkatPem;
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 a PEM file that has the certificate and its private key. The 1st argument of LoadPemFile is
// the path and the 2nd is the password of the private key (from a secure source).
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;
// Add the certificates and private keys of the Pem object as a source for later decryption.
// Call AddPemSource once per source. Each call adds more certificates to the ones already added.
success := mime.AddPemSource(pem.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(mime.LastErrorText);
Exit;
end;
// Decrypt using the keys from the added PEM source(s).
success := mime.Decrypt();
if (success = 0) then
begin
Memo1.Lines.Add(mime.LastErrorText);
Exit;
end;
Memo1.Lines.Add('Decrypted.');