API referenceEncryption

pdfTestPassword

Clear any armed encryption, report the current encryption

C
BOOL32 __stdcall pdfResetEncryptionSettings(PPDF IPDF);
BOOL32 __stdcall pdfGetInEncryptionInfo(PPDF IPDF, TPDFEncryptInfo* Info);
BOOL32 __stdcall pdfTestPassword(PPDF IPDF, TPwdType PwdType, const char* Value);
Delphi
function pdfResetEncryptionSettings(const IPDF: PPDF): LongBool; stdcall;
function pdfGetInEncryptionInfo(const IPDF: PPDF; var Info: TPDFEncryptInfo): LongBool; stdcall;
function pdfTestPassword(const IPDF: PPDF; PwdType: TPwdType; const Value: PAnsiChar): LongBool; stdcall;

Purpose. Clear any armed encryption, report the current encryption configuration, and test a candidate password against the currently-set open/owner passwords.

Description. pdfResetEncryptionSettings genuinely zeroes all crypto state (FEncryptDoc := False, key length, both passwords, permissions) — a real, complete reset, not merely a flag flip. pdfGetInEncryptionInfo reports FCryptKeyLen/whether each password is set/the permission bitmask — Info.UnsafeOpenPwd/UnsafeOwnerPwd are always hardcoded False, despite their names implying a real weak-password heuristic; no such check is performed anywhere. Despite the "In" naming convention used elsewhere in this SDK for import-source inspectors (pdfGetInFieldCount, pdfGetInIsSigned, etc., which all inspect FImportSrc), pdfGetInEncryptionInfo reports the live document's own SetEncryption-armed state, not the import source's — an inconsistency with the "In" naming convention used elsewhere (contrast pdfGetInEncryptionFlags below, which genuinely does inspect the import source). pdfTestPassword always returns True if the document isn't currently encrypted at all (not FEncryptDoc) — regardless of what Value is, even an empty or garbage string — since an unencrypted document accepts any "password." When encrypted, it checks Value against the owner password only (PwdType = ptOwner) or against either the user or owner password otherwise.

Parameters.

ParameterDescription
IPDFDocument handle.
InfoOutput: Filter (key length), HaveOpenPassword/HaveOwnerPassword, Restrictions; UnsafeOpenPwd/UnsafeOwnerPwd always False.
PwdTypeptOwner tests against the owner password only; anything else accepts either password.
ValueCandidate password to test.

Return value. pdfResetEncryptionSettings: always True if IPDF resolves. pdfGetInEncryptionInfo: True if IPDF resolves. pdfTestPassword: True if the document is unencrypted, or Value matches per the rules above.

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
[return: MarshalAs(UnmanagedType.Bool)]
Area
Encryption
Category

Core

Exported names

pdfTestPassword

String variants

The …A form takes UTF-8, …W takes UTF-16; a bare name aliases the ANSI form.

See working code

Worked examples — complete programs in ten languages.