Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -522,13 +522,15 @@ private void prepareEncryptionDictRev234(String ownerPassword, String userPasswo
COSArray idArray = document.getDocument().getDocumentID();

//check if the document has an id yet. If it does not then generate one
byte[] userPasswordBytes = userPassword.getBytes(StandardCharsets.ISO_8859_1);
byte[] ownerPasswordBytes = ownerPassword.getBytes(StandardCharsets.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(StandardCharsets.ISO_8859_1));
md.update(userPassword.getBytes(StandardCharsets.ISO_8859_1));
md.update(ownerPasswordBytes);
md.update(userPasswordBytes);
md.update(document.getDocument().toString().getBytes(StandardCharsets.ISO_8859_1));

byte[] id = md.digest(this.toString().getBytes(StandardCharsets.ISO_8859_1));
Expand All @@ -541,14 +543,15 @@ private void prepareEncryptionDictRev234(String ownerPassword, String userPasswo
COSString id = (COSString) idArray.getObject(0);

byte[] ownerBytes = computeOwnerPassword(
ownerPassword.getBytes(StandardCharsets.ISO_8859_1),
userPassword.getBytes(StandardCharsets.ISO_8859_1), revision, length);
ownerPasswordBytes,
userPasswordBytes, revision, length);

byte[] idBytes = id.getBytes();
byte[] userBytes = computeUserPassword(
userPassword.getBytes(StandardCharsets.ISO_8859_1),
ownerBytes, permissionInt, id.getBytes(), revision, length, true);
userPasswordBytes,
ownerBytes, permissionInt, idBytes, revision, length, true);

setEncryptionKey(computeEncryptedKeyRev234(userPassword.getBytes(StandardCharsets.ISO_8859_1), ownerBytes, permissionInt, id.getBytes(), true, length, revision));
setEncryptionKey(computeEncryptedKeyRev234(userPasswordBytes, ownerBytes, permissionInt, idBytes, true, length, revision));

encryptionDictionary.setOwnerKey(ownerBytes);
encryptionDictionary.setUserKey(userBytes);
Expand Down