THotPDF.CryptKeyLength Property

 

THotPDF.CryptKeyLength

THotPDF

 

Đầu trang  Trước  Tiếp

Xác định phương thức mã hóa của tệp PDF

 

type

THPDFKeyType = ( k40,  k128,  aes128,  aes256 );

 

Delphi syntax:

property CryptKeyLength: THPDFKeyType;

 

C++ syntax:

__property THPDFKeyType CryptKeyLength;

 

Mô tả

Dùng CryptKeyLength để chọn revision của standard security handler và cipher được dùng khi ActivateProtection được bật

 

Value                Meaning


k40                        Standard security handler V=1, R=2, RC4 với khóa 40-bit (PDF 1.1+)

k128                        Standard security handler V=2, R=3, RC4 với khóa 128-bit (PDF 1.4+)

aes128                  Standard security handler V=4, R=4 với crypt filter StdCF (CFM=AESV2). AES-128 ở chế độ CBC với PKCS#7 padding và IV ngẫu nhiên 16 byte theo ISO 32000-1 7.6.2 / 7.4.4.2 (PDF 1.6+). Từ HotPDF v2.4.0 tùy chọn này mã hóa string và stream bằng cài đặt AES thực; các bản trước chỉ xuất dict AES mà chưa mã hóa nội dung

aes256                  Standard security handler V=5 với crypt filter StdCF (CFM=AESV3). AES-256 ở chế độ CBC với PKCS#7 padding và IV ngẫu nhiên 16 byte theo Adobe Extension Level 3 / ISO 32000-2 7.6.4 (PDF 1.7+, được Acrobat 9 trở lên, Foxit, Chrome và các trình xem của Apple/macOS chấp nhận). Có từ HotPDF v2.17.0. Revision mặc định là R=5 với băm mật khẩu SHA-256. Đặt UseAES256R6 thành true để chuyển sang R=6 với thuật toán 2.B của ISO 32000-2 theo kiểu "hash dance" (SHA-256 / SHA-384 / SHA-512 + AES-128 mixer); R=6 là bắt buộc với Acrobat DC và các trình kiểm tra PDF/A-4. Có từ HotPDF v2.22.0

 

Public-Key Security Handler (PDF 1.7 7.6.5)

Với mã hóa dựa trên chứng chỉ (một tài liệu, nhiều người nhận) hãy gọi EnablePubKeyEncryption(seed, KeyType, EncryptMetadata) thay vì đặt UserPassword / OwnerPassword. Các giá trị CryptKeyLength tương ứng vẫn áp dụng cho cipher đối xứng (k40 -> RC4-40 / V=1 + s4 SubFilter, k128 -> RC4-128 / V=2 + s5, aes128 -> AES-128 / V=4 + s5). Người gọi phải tự tạo một blob PKCS#7 envelopedData cho mỗi người nhận (Windows CryptoAPI, OpenSSL hoặc pycryptodome) và thêm từng blob qua AddPubKeyRecipient; khóa mã hóa của tệp được suy ra bằng thuật toán 9 (SHA-1 của seed ghép với các binary của envelope). Có từ HotPDF v2.33.0

 

Ví dụ mã

HPDF.OwnerPassword := 'password';          // Set owner password (required to change security settings)
HPDF.UserPassword := 'user';               // Set user password (required to open the document)
HPDF.ProtectOptions := [poEdit, poAnnot];  // Disallow editing and annotations
HPDF.ActivateProtection := true;           // Enable PDF security

 

See also: ActivateProtection, OwnerPassword, ProtectOptions, UserPassword