SM4EncryptCBCPKCS7
Cryptography
Description
Encrypts a payload of any length with SM4 in CBC mode, applying PKCS#7 padding before the cipher runs
Syntax
Delphi
Function SM4EncryptCBCPKCS7(Const Key, IV, Plaintext: AnsiString): AnsiString;Parameters
| Key | Exactly 16 bytes |
|---|---|
| IV | Exactly 16 bytes; each block is chained with the previous ciphertext block |
| Plaintext | Any length; padded to the next 16-byte boundary before encryption |
Return values
| The padded ciphertext, or an empty string on any invalid input |
Remarks
Part of the pure-Pascal SM4 block cipher (GB/T 32907-2016)
The PKCS#7 layer appends 1..16 pad bytes so the payload becomes a multiple of the 16-byte block size; a full block is added when the input is already aligned
Decrypt the result with SM4DecryptCBCPKCS7; the unpadded pair SM4EncryptCBC/SM4DecryptCBC requires block-aligned input
See also
SM4DecryptCBCPKCS7, SM4EncryptCBC, SM4EncryptECBPKCS7, SM4PadPKCS7