TPdfEncryptionRevision = (erR5, erR6, erR7);
TPdfEncryptOptions = record
UserPassword: AnsiString;
OwnerPassword: AnsiString;
Permissions: Cardinal;
EncryptMetadata: Boolean;
Revision: TPdfEncryptionRevision;
EnableIntegrityProtection: Boolean;
class function Default: TPdfEncryptOptions; static;
end;
TPdfEncryptionKeys = record
FileEncryptionKey: TBytes;
OEntry: TBytes;
UEntry: TBytes;
OEEntry: TBytes;
UEEntry: TBytes;
PermsEntry: TBytes;
KdfSalt: TBytes;
end;
TPdfIncrementalEncryptionContext = record
FileEncryptionKey: TBytes;
KdfSalt: TBytes;
Revision: TPdfEncryptionRevision;
EncryptMetadata: Boolean;
EncryptObjectNumber: Integer;
EncryptGeneration: Integer;
HasAuthenticationCode: Boolean;
end;
procedure DeriveEncryptionKeys(const Options: TPdfEncryptOptions;
out Keys: TPdfEncryptionKeys);
function BuildEncryptDictionary(const Keys: TPdfEncryptionKeys;
const Options: TPdfEncryptOptions): AnsiString;
function EncryptStreamPayload(const FileKey: TBytes;
const Plain: TBytes): TBytes;
function EncryptDocumentBytes(const PlainPdf: TBytes;
const Options: TPdfEncryptOptions): TBytes;
function DecryptAesGcmDocumentBytes(const EncryptedPdf: TBytes;
const Password: AnsiString; out PlainPdf: TBytes;
out ErrorText: string): Boolean;
function ValidateEncryptedDocumentMac(const EncryptedPdf: TBytes;
const Password: AnsiString): TPdfMacValidationResult;
function ReadIncrementalEncryptionContext(const EncryptedPdf: TBytes;
const Password: AnsiString;
out Context: TPdfIncrementalEncryptionContext;
out ErrorText: string): Boolean;
procedure ClearIncrementalEncryptionContext(
var Context: TPdfIncrementalEncryptionContext);
function EncryptIncrementalObjectBody(const PlainBody: TBytes;
const Context: TPdfIncrementalEncryptionContext;
out EncryptedBody: TBytes;
out ErrorText: string): Boolean;
FPdfEncrypt는 ISO 32000-2 §7.6에 정의된 PDF AES-256 보안 핸들러와 ISO/TS 32003이 정의한 AESV4-GCM 확장을 구현합니다. EncryptDocumentBytes는 평문 PDF 바이트 배열을 선택된 리비전으로 암호화된 문서로 바꿉니다
DeriveEncryptionKeys는 암호 기반 키 유도를 실행해 32바이트 파일 암호화 키와 /O, /U, /OE, /UE, /Perms 사전 항목을 만듭니다. BuildEncryptDictionary는 그 항목들을 /Encrypt 사전 텍스트로 직렬화합니다. EncryptStreamPayload는 파일 키로 단일 객체 스트림에 AES-256-CBC 암호화를 적용합니다
사용자 지정 저장 파이프라인을 만드는 고급 사용자는 세 프리미티브를 직접 호출할 수 있습니다. 애플리케이션 코드는 보통 내부적으로 EncryptDocumentBytes를 호출하는 TPdf.SaveAsEncrypted나 TPdf.SaveAsEncryptedToStream을 사용합니다
EnableIntegrityProtection이 true이면 라이터는 EOF 전체를 덮는 /ByteRange, /KDFSalt, CMS AuthenticatedData, HKDF-SHA256, AES-256 Key Wrap, HMAC-SHA256을 갖춘 PDF 2.0 ISO/TS 32004 독립 인증 코드를 출력합니다
PDFium은 현재 공개 ABI를 통해 AESV4 파싱을 노출하지 않습니다. 먼저 DecryptAesGcmDocumentBytes를 호출하고 반환된 바이트를 TPdf.LoadDocument에 넘기세요. 암호, 권한, PDF MAC, 문자열 태그, 스트림 태그 실패 시에는 부분 평문을 반환하지 않습니다
ReadIncrementalEncryptionContext는 현재 암호화된 리비전 체인을 인증하고 상속된 보안 상태를 복구합니다. EncryptIncrementalObjectBody는 메타데이터 제외를 유지하고 직접 /Length 값을 갱신하면서 바뀐 간접 객체 하나의 문자열과 스트림 페이로드를 암호화합니다. ClearIncrementalEncryptionContext는 복구된 키 자료를 지웁니다
| Function | Description |
|---|---|
DeriveEncryptionKeys | 암호 기반 키 유도를 실행하고 파일 키와 다섯 사전 항목을 반환합니다 |
BuildEncryptDictionary | 키와 옵션을 /Encrypt 사전 텍스트로 직렬화합니다 |
EncryptStreamPayload | 파일 키로 하나의 객체 스트림을 AES-256-CBC로 암호화합니다 |
EncryptDocumentBytes | 키를 유도하고 스트림을 재작성하며 전체 PDF 바이트 배열에 /Encrypt 사전을 삽입하는 일회용 헬퍼입니다 |
DecryptAesGcmDocumentBytes | AESV4-GCM 출력을 인증·복호화해 PDFium이 로드할 수 있는 평문 바이트로 만듭니다 |
ValidateEncryptedDocumentMac | 사용자 또는 소유자 암호로 원본 암호화 바이트에 대해 독립 PDF MAC을 검증합니다 |
ReadIncrementalEncryptionContext | 암호화된 리비전 체인을 인증하고 상속된 파일 키, 리비전, 메타데이터 정책, /Encrypt 참조, PDF MAC 상태를 복구합니다 |
ClearIncrementalEncryptionContext | 복구된 증분 암호화 키 자료를 안전하게 지웁니다 |
EncryptIncrementalObjectBody | 상속된 보안 컨텍스트 아래에서 바뀐 간접 객체 본문 하나의 문자열과 스트림을 암호화합니다 |
| Type | Description |
|---|---|
TPdfEncryptionRevision | AESV3-CBC 리비전 erR5나 erR6, 또는 ISO/TS 32003 AESV4-GCM 리비전 erR7을 고르는 열거형입니다 |
TPdfEncryptOptions | 암호, 권한 플래그, 메타데이터 정책, 보안 핸들러 리비전, 선택적 PDF MAC 무결성 보호를 담는 레코드입니다 |
TPdfEncryptionKeys | 파일 키, 보안 핸들러 항목, 선택적 32바이트 /KDFSalt를 담는 레코드입니다 |
TPdfIncrementalEncryptionContext | 기존 /Encrypt 사전을 교체하지 않고 암호화된 간접 객체를 덧붙이는 데 쓰이는, 인증된 상속 보안 상태입니다 |
TPdfMacValidationStatus | pmvsValid, pmvsNotPresent, pmvsInvalid, pmvsUnsupported |
TPdfMacValidationResult | 독립 PDF MAC 검증 Status와 진단 MessageText |
DecryptAesGcmDocumentBytes는 암호화 증분 라이터가 출력한 클래식 /Prev 리비전 체인을 따라가 최신 활성 객체 세대를 해석합니다. 이 릴리스에서는 네이티브 PDFium AESV4 로딩과 외부 xref 스트림 AESV4 입력을 사용할 수 없습니다Permissions는 ISO 32000-1 Table 22(/P 플래그)의 비트 배치를 사용합니다