PDFSM4DecryptString

Cryptography

Description

Decrypts an IV-prefixed SM4-CBC string produced by PDFSM4EncryptString and strips the PKCS#7 padding

Syntax

Delphi

Function PDFSM4DecryptString(Const Key, Ciphertext: AnsiString): AnsiString;

Parameters

KeyExactly 16 bytes
CiphertextAt least 32 bytes and a multiple of 16; the first 16 bytes are the IV

Return values

The unpadded plaintext, or an empty string when the input is malformed or the padding check fails

Remarks

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

A wrong key surfaces as a padding failure and yields an empty result

For ciphertext held in a raw buffer use PDFSM4DecryptStringBuffer instead of copying it into an AnsiString first

See also

PDFSM4EncryptString, PDFSM4DecryptStringBuffer, SM4DecryptCBCPKCS7