THotPDF.CryptKeyLength Property

 

使用 CryptKeyLength 選擇 ActivateProtection 啟用時使用的 standard security handler revision 與 cipher

THotPDF

 

傳回頂部  上一頁  下一頁

Determines PDF file encryption method

 

type

aes128 標準安全處理器 V=4、R=4,搭配加密篩選器 StdCF(CFM=AESV2)。依 ISO 32000-1 7.6.2 / 7.4.4.2(PDF 1.6+),使用 CBC mode、PKCS#7 padding 與每次 16-byte random initialization vector 的 AES-128。自 HotPDF v2.4.0 起,此選項會以真實 AES 實作加密 strings 與 streams;更早 builds 只輸出 AES dictionary,但未實際加密 content

 

Delphi 語法:

property CryptKeyLength: THPDFKeyType;

 

C++ 語法:

__property THPDFKeyType CryptKeyLength;

 

說明

使用 CryptKeyLength 選擇 ActivateProtection 啟用時使用的 standard security handler revision 與 cipher

 EncryptMetadata to false before BeginDoc to write /EncryptMetadata false, leave XMP /Metadata streams cleartext, and use the matching AES-128 key derivation or AES-256 /Perms metadata flag. The default is true for compatibility

 

數值意義


k40                        Standard security handler V=1, R=2, RC4 with a 40-bit key (PDF 1.1+)

k128                        Standard security handler V=2, R=3, RC4 with a 128-bit key (PDF 1.4+)

aes128                  標準安全處理器 V=4、R=4,搭配加密篩選器 StdCF(CFM=AESV2)。依 ISO 32000-1 7.6.2 / 7.4.4.2(PDF 1.6+),使用 CBC mode、PKCS#7 padding 與每次 16-byte random initialization vector 的 AES-128。自 HotPDF v2.4.0 起,此選項會以真實 AES 實作加密 strings 與 streams;更早 builds 只輸出 AES dictionary,但未實際加密 content

aes256 標準安全處理器 V=5,搭配 crypt filter StdCF (CFM=AESV3)。依 Adobe Extension Level 3 / ISO 32000-2 7.6.4 (PDF 1.7+),使用 CBC mode、PKCS#7 padding 與 16-byte random initialization vector 的 AES-256;Acrobat 9 與更新版本、Foxit、Chrome 以及 Apple/macOS viewers 接受此設定。自 HotPDF v2.17.0 起可用。選擇 aes256 時,若輸出版本較低會一併提升到 PDF 1.7;除非設了 StrictVersionLock,此時較低的版本會退回 AES-128(v2.760.0 之前,預設的 PDF 1.6 輸出會默默退回 AES-128)。預設 revision 是 R=5 並使用 SHA-256 password hashing。將 UseAES256R6 設為 true 可切換到 R=6,使用 ISO 32000-2 algorithm 2.B “hash dance”(SHA-256 / SHA-384 / SHA-512 + AES-128 mixer);Acrobat DC 與 PDF/A-4 validators 要求 R=6。自 HotPDF v2.22.0 起可用

aesgcm              Standard security handler V=6, R=7 with crypt filter StdCF (CFM=AESV4). AES-256-GCM uses a unique 12-byte initialization vector and a 16-byte authentication tag for every encrypted string and stream, with empty additional authenticated data, as defined by ISO/TS 32003:2023. This option requires PDF 2.0 and emits the ISO developer extension at extension level 32003. Available since HotPDF v2.475.0

 

Public-Key Security Handler (ISO 32000-1 7.6.4, ISO 32000-2 7.6.5)

對於 certificate-based encryption(一份 document、多個 recipients),請呼叫 EnablePubKeyEncryption(seed, KeyType, EncryptMetadata),而不是設定 UserPassword / OwnerPassword。Public-key encryption 支援 k40、k128、aes128 與 aes256(aes256 會把輸出提升到 PDF 2.0,certificate 或 key-agreement recipients 也需要它);aesgcm 則限於密碼式的 standard security handler。Caller 必須為每個 recipient 建立一個 PKCS#7 envelopedData blob(Windows CryptoAPI、OpenSSL 或 pycryptodome),並透過 AddPubKeyRecipient 附加每個 blob;file encryption key 依 ISO 32000-1 7.6.4.3 推導(seed 與 envelope binaries 串接後的 SHA-1)。自 HotPDF v2.33.0 起可用

 

Code Example

HPDF.OwnerPassword := 'password';          // Set owner password (required to change security settings)
HPDF.UserPassword := 'user';               // Set user password (required to open the document)
HPDF.ProtectOptions := [prPrint, prPrint12bit]; // Allow full-quality printing only
HPDF.ActivateProtection := true;           // Enable PDF security

 

請參閱: ActivateProtection, OwnerPassword, ProtectOptions, UserPassword