On which OS are you (OS, type and version)?
You can try this site: GitHub - ArturT/Test-PDF-Files: Example PDF files. You can use them to test how your app works with encrypted, not encrypted and corrupted files.
There, you will find a regular PDF, an encrypted one, and a corrupted one. The offer is quite old, but maybe sufficient just for testing.
On opening AND viewing the encrypted PDF, I got:
gunnersson@tulicube:~/Downloads> okular encrypted.pdf
Couldn't start kwalletd: QDBusError("org.freedesktop.DBus.Error.ServiceUnknown", "The name org.kde.kwalletd5 was not provided by any .service files")
Couldn't start kwalletd: QDBusError("org.freedesktop.DBus.Error.ServiceUnknown", "The name org.kde.kwalletd5 was not provided by any .service files")
Couldn't start kwalletd: QDBusError("org.freedesktop.DBus.Error.ServiceUnknown", "The name org.kde.kwalletd5 was not provided by any .service files")
Couldn't start kwalletd: QDBusError("org.freedesktop.DBus.Error.ServiceUnknown", "The name org.kde.kwalletd5 was not provided by any .service files")
Couldn't start kwalletd: QDBusError("org.freedesktop.DBus.Error.ServiceUnknown", "The name org.kde.kwalletd5 was not provided by any .service files")
Couldn't start kwalletd: QDBusError("org.freedesktop.DBus.Error.ServiceUnknown", "The name org.kde.kwalletd5 was not provided by any .service files")
QWidget::setMinimumSize: (okular_sidebar/Sidebar) Negative sizes (0,-1) are not possible
But it displayed properly.