PDFSM4EncryptString
Cryptography
Description
Encrypts a string of any length with SM4-CBC under a 16-byte key, prefixing the ciphertext with a fresh random 16-byte IV
Syntax
Delphi
Function PDFSM4EncryptString(Const Key, Plaintext: AnsiString): AnsiString;Parameters
| Key | Exactly 16 bytes |
|---|---|
| Plaintext | Any length; padded with PKCS#7 before encryption |
Return values
| The 16-byte IV followed by the padded ciphertext, or an empty string when the key is malformed or the secure random source fails |
Remarks
Part of the pure-Pascal SM4 block cipher (GB/T 32907-2016)
Every call produces different output because the IV comes from the secure random generator; store or transmit the full IV-prefixed blob and decrypt it with PDFSM4DecryptString
The output length for a given plaintext size is available in advance from PDFSM4EncryptedLength
See also
PDFSM4DecryptString, PDFSM4EncryptToStream, PDFSM4EncryptedLength, SM4EncryptCBCPKCS7