PLDecryptPurePubSecEnvelope

Cryptography

Description

Decrypts a PKCS#7 EnvelopedData envelope built by PLBuildPurePubSecEnvelope or another CMS producer, using a recipient RSA, EC or SM2 private key

Syntax

Delphi

Function PLDecryptPurePubSecEnvelope(Const Envelope,
  PrivateKeyDER: AnsiString; Out Plaintext: AnsiString): Boolean;

Parameters

EnvelopeThe DER-encoded EnvelopedData structure
PrivateKeyDERDER-encoded RSA private key of a recipient
PlaintextReceives the decrypted, padding-stripped payload; empty on failure

Return values

TrueThe content-encryption key was unwrapped and the payload decrypted
FalseThe envelope is malformed, the private key does not match a recipient, or the structure is unsupported

Remarks

Parses the ContentInfo wrapper and walks the RecipientInfos set: RSA keys open key transport recipients, EC keys carry out the RFC 5753 ECDH key agreement and unwrap the AES key-wrapped content key, and SM2 keys decrypt sm2encrypt recipients and check the embedded SM3 hash; the payload is then decrypted under AES-256-CBC or SM4-CBC as indicated by the embedded cipher OID

An AES key-wrap integrity failure, an SM2 hash mismatch or invalid padding moves the routine on to the next recipient, so a key the envelope does not address returns False

Counterpart of PLBuildPurePubSecEnvelope

See also

PLBuildPurePubSecEnvelope, PLDecryptPKCS8PrivateKey