PLBuildPurePubSecEnvelope

Cryptography

Description

Builds a PKCS#7 EnvelopedData envelope (OID 1.2.840.113549.1.7.3) for one or more recipient certificates entirely in pure Pascal

Syntax

Delphi

Function PLBuildPurePubSecEnvelope(Const Plaintext: AnsiString;
  Const CertDERs: Array Of AnsiString; Out Envelope: AnsiString): Boolean;

Parameters

PlaintextThe payload to envelop; must not be empty
CertDERsDER-encoded recipient certificates; every entry must parse and at least one is required
EnvelopeReceives the DER-encoded EnvelopedData structure; empty on failure

Return values

TrueThe envelope was built with one recipient info per certificate
FalseThe plaintext is empty, no certificate was supplied, or a certificate failed to parse

Remarks

The payload is encrypted under a fresh content-encryption key with AES-256-CBC; when any recipient certificate carries an SM2 public key the content cipher switches to SM4-CBC (GB/T 32907-2016) so the same envelope serves SM2 recipients

The content-encryption key, IV and RSA padding all come from the system secure random source, so building the same payload twice gives different envelopes

The content-encryption key is protected per recipient:

An EC or SM2 envelope is version 2 when it carries a key agreement recipient, and standard CMS tools such as OpenSSL cms -decrypt can open the RSA and EC recipients

Decrypt with PLDecryptPurePubSecEnvelope using the matching recipient private key

See also

PLDecryptPurePubSecEnvelope, PLCertificatePublicKeyInfo, PLSplitCertificateBundle