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
| Plaintext | The payload to envelop; must not be empty |
|---|---|
| CertDERs | DER-encoded recipient certificates; every entry must parse and at least one is required |
| Envelope | Receives the DER-encoded EnvelopedData structure; empty on failure |
Return values
| True | The envelope was built with one recipient info per certificate |
|---|---|
| False | The plaintext is empty, no certificate was supplied, a certificate failed to parse, or a recipient key type or curve is unsupported |
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 come from the system secure random source, so building the same payload twice yields different envelopes
The content-encryption key is protected per recipient:
- RSA certificates use RSAES-PKCS1-v1_5 key transport
- EC certificates on P-256, P-384 and the Brainpool P256r1, P384r1 and P512r1 curves use an RFC 5753 key agreement: ephemeral-static ECDH with the dhSinglePass-stdDH-sha256kdf scheme and AES-256 key wrap
- SM2 certificates use GB/T 32918.4 SM2 public-key encryption (sm2encrypt, 1.2.156.10197.1.301.3)
An EC or SM2 envelope is version 2 when it contains 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