С SetaPDF-Core можно пройти аутентификацию в зашифрованном / защищенном PDF-документе:
$document = SetaPDF_Core_Document::loadByFilename('encrypted.pdf');
Чтобы проверить, зашифрован ли документ, вы можете просто проверить его на безопасность. обработчик:
$isEncrypted = $document->hasSecHandler();
В зависимости от этой информации вы можете получить доступ к обработчику безопасности:
if ($isEncrypted) {
// get the security handler
$secHandler = $document->getSecHandler();
// authenticate with a password without knowing if it is the owner or user password:
if ($secHandler->auth('a secret password')) {
echo 'authenticated as ' . $secHandler->getAuthMode();
} else {
echo 'authentication failed - neither user nor owner password did match.';
}
// authenticate with the user password:
if ($secHandler->authByUserPassword('a secret password')) {
echo 'authenticated as user';
} else {
echo 'authentication failed with the user password.';
}
// authenticate with the owner password:
if ($secHandler->authByOwnerPassword('a secret password')) {
echo 'authenticated as owner';
} else {
echo 'authentication failed with the owner password.';
}
}
(Это также возможно с помощью закрытого ключа и сертификата, если документ зашифрован с помощью его ключ publi c - для получения дополнительной информации см. здесь )
Если вы аутентифицированы как владелец, вы можете удалить обработчик securtiy из документа:
if ($secHandler->getAuthMode() === SetaPDF_Core_SecHandler::OWNER) {
$document->setSecHandler(null);
$writer = new SetaPDF_Core_Writer_File('not-encrypted.pdf');
$document->setWriter($writer);
$document->save()->finish();
}