PDFSM4TryDecryptStringBuffer

Cryptography

Description

The buffer form of PDFSM4TryDecryptString: it decrypts an IV-prefixed SM4-CBC payload held in a raw memory buffer, so ciphertext read straight from a stream or a mapped region does not have to be copied into an AnsiString first.

The contract is identical: a 16-byte key, a buffer of at least 32 bytes whose length is a multiple of 16, the first 16 bytes as the IV, CBC decryption, then a PKCS#7 padding check that turns a wrong key into a clean false.

Syntax

Delphi

Function PDFSM4TryDecryptStringBuffer(Const Key: AnsiString;
  Ciphertext: Pointer; CiphertextLength: Integer;
  Out Plaintext: AnsiString): Boolean;

Parameters

KeyExactly 16 bytes
CiphertextPointer to the encrypted bytes; nil fails immediately
CiphertextLengthAt least 32 and a multiple of 16
PlaintextReceives the unpadded plaintext on success; set to an empty string on failure

Return values

TrueThe payload decrypted and carried valid PKCS#7 padding
FalseThe pointer is nil, the lengths violate the contract or the padding check failed

Remarks

Part of the pure-Pascal SM4 block cipher (GB/T 32907-2016).

See also

PDFSM4DecryptStringBuffer, PDFSM4DecryptString, PDFSM4EncryptString, SM4TryUnpadPKCS7