Author: tilman
Date: Wed Apr 8 07:52:51 2026
New Revision: 1932893
Log:
PDFBOX-5660: optimize, as suggested by Valery Bokov; closes #432
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
==============================================================================
---
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
Wed Apr 8 07:52:48 2026 (r1932892)
+++
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
Wed Apr 8 07:52:51 2026 (r1932893)
@@ -511,13 +511,15 @@ public final class StandardSecurityHandl
COSArray idArray = document.getDocument().getDocumentID();
//check if the document has an id yet. If it does not then generate
one
+ byte[] userPasswordBytes = userPassword.getBytes(Charsets.ISO_8859_1);
+ byte[] ownerPasswordBytes =
ownerPassword.getBytes(Charsets.ISO_8859_1);
if (idArray == null || idArray.size() < 2)
{
MessageDigest md = MessageDigests.getMD5();
BigInteger time = BigInteger.valueOf(System.currentTimeMillis());
md.update(time.toByteArray());
- md.update(ownerPassword.getBytes(Charsets.ISO_8859_1));
- md.update(userPassword.getBytes(Charsets.ISO_8859_1));
+ md.update(ownerPasswordBytes);
+ md.update(userPasswordBytes);
md.update(document.getDocument().toString().getBytes(Charsets.ISO_8859_1));
byte[] id =
md.digest(this.toString().getBytes(Charsets.ISO_8859_1));
@@ -532,15 +534,16 @@ public final class StandardSecurityHandl
COSString id = (COSString) idArray.getObject(0);
byte[] ownerBytes = computeOwnerPassword(
- ownerPassword.getBytes(Charsets.ISO_8859_1),
- userPassword.getBytes(Charsets.ISO_8859_1), revision, length);
+ ownerPasswordBytes,
+ userPasswordBytes, revision, length);
+ byte[] idBytes = id.getBytes();
byte[] userBytes = computeUserPassword(
- userPassword.getBytes(Charsets.ISO_8859_1),
- ownerBytes, permissionInt, id.getBytes(), revision, length,
true);
+ userPasswordBytes,
+ ownerBytes, permissionInt, idBytes, revision, length, true);
-
setEncryptionKey(computeEncryptedKey(userPassword.getBytes(Charsets.ISO_8859_1),
ownerBytes,
- null, null, null, permissionInt, id.getBytes(), revision,
length, true, false));
+ setEncryptionKey(computeEncryptedKey(userPasswordBytes, ownerBytes,
+ null, null, null, permissionInt, idBytes, revision, length,
true, false));
encryptionDictionary.setOwnerKey(ownerBytes);
encryptionDictionary.setUserKey(userBytes);