You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2015/03/24 23:20:55 UTC
svn commit: r1669009 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
Author: tilman
Date: Tue Mar 24 22:20:54 2015
New Revision: 1669009
URL: http://svn.apache.org/r1669009
Log:
PDFBOX-2576: better names
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java?rev=1669009&r1=1669008&r2=1669009&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java Tue Mar 24 22:20:54 2015
@@ -37,8 +37,7 @@ import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSString;
import org.apache.pdfbox.pdmodel.PDDocument;
-import static org.apache.pdfbox.util.Charsets.ISO_8859_1_CHARSET;
-import static org.apache.pdfbox.util.Charsets.UTF_8_CHARSET;
+import org.apache.pdfbox.util.Charsets;
/**
* The standard security handler. This security handler protects document with password.
@@ -186,10 +185,10 @@ public final class StandardSecurityHandl
byte[] ownerKey = encryption.getOwnerKey();
byte[] ue = null, oe = null;
- Charset passwordCharset = ISO_8859_1_CHARSET;
+ Charset passwordCharset = Charsets.ISO_8859_1;
if (dicRevision == 6 || dicRevision == 5)
{
- passwordCharset = UTF_8_CHARSET;
+ passwordCharset = Charsets.UTF_8;
ue = encryption.getUserEncryptionKey();
oe = encryption.getOwnerEncryptionKey();
}
@@ -387,7 +386,7 @@ public final class StandardSecurityHandl
rnd.nextBytes(encryptionKey);
// Algorithm 8a: Compute U
- byte[] userPasswordBytes = truncate127(userPassword.getBytes(UTF_8_CHARSET));
+ byte[] userPasswordBytes = truncate127(userPassword.getBytes(Charsets.UTF_8));
byte[] userValidationSalt = new byte[8];
byte[] userKeySalt = new byte[8];
rnd.nextBytes(userValidationSalt);
@@ -404,7 +403,7 @@ public final class StandardSecurityHandl
byte[] ue = cipher.doFinal(encryptionKey);
// Algorithm 9a: Compute O
- byte[] ownerPasswordBytes = truncate127(ownerPassword.getBytes(UTF_8_CHARSET));
+ byte[] ownerPasswordBytes = truncate127(ownerPassword.getBytes(Charsets.UTF_8));
byte[] ownerValidationSalt = new byte[8];
byte[] ownerKeySalt = new byte[8];
rnd.nextBytes(ownerValidationSalt);
@@ -479,11 +478,11 @@ public final class StandardSecurityHandl
MessageDigest md = MessageDigests.getMD5();
BigInteger time = BigInteger.valueOf(System.currentTimeMillis());
md.update(time.toByteArray());
- md.update(ownerPassword.getBytes(ISO_8859_1_CHARSET));
- md.update(userPassword.getBytes(ISO_8859_1_CHARSET));
+ md.update(ownerPassword.getBytes(Charsets.ISO_8859_1));
+ md.update(userPassword.getBytes(Charsets.ISO_8859_1));
md.update(document.getDocument().toString().getBytes());
- byte[] id = md.digest(this.toString().getBytes(ISO_8859_1_CHARSET));
+ byte[] id = md.digest(this.toString().getBytes(Charsets.ISO_8859_1));
COSString idString = new COSString(id);
idArray = new COSArray();
@@ -495,14 +494,14 @@ public final class StandardSecurityHandl
COSString id = (COSString) idArray.getObject(0);
byte[] ownerBytes = computeOwnerPassword(
- ownerPassword.getBytes(ISO_8859_1_CHARSET),
- userPassword.getBytes(ISO_8859_1_CHARSET), revision, length);
+ ownerPassword.getBytes(Charsets.ISO_8859_1),
+ userPassword.getBytes(Charsets.ISO_8859_1), revision, length);
byte[] userBytes = computeUserPassword(
- userPassword.getBytes(ISO_8859_1_CHARSET),
+ userPassword.getBytes(Charsets.ISO_8859_1),
ownerBytes, permissionInt, id.getBytes(), revision, length, true);
- encryptionKey = computeEncryptedKey(userPassword.getBytes(ISO_8859_1_CHARSET), ownerBytes,
+ encryptionKey = computeEncryptedKey(userPassword.getBytes(Charsets.ISO_8859_1), ownerBytes,
null, null, null, permissionInt, id.getBytes(), revision, length, true, false);
encryptionDictionary.setOwnerKey(ownerBytes);
@@ -958,12 +957,12 @@ public final class StandardSecurityHandl
{
if (encRevision == 6 || encRevision == 5)
{
- return isUserPassword(password.getBytes(UTF_8_CHARSET), user, owner, permissions, id,
+ return isUserPassword(password.getBytes(Charsets.UTF_8), user, owner, permissions, id,
encRevision, length, encryptMetadata);
}
else
{
- return isUserPassword(password.getBytes(ISO_8859_1_CHARSET), user, owner, permissions, id,
+ return isUserPassword(password.getBytes(Charsets.ISO_8859_1), user, owner, permissions, id,
encRevision, length, encryptMetadata);
}
}
@@ -988,7 +987,7 @@ public final class StandardSecurityHandl
byte[] id, int encRevision, int length, boolean encryptMetadata)
throws IOException
{
- return isOwnerPassword(password.getBytes(ISO_8859_1_CHARSET), user,owner,permissions, id,
+ return isOwnerPassword(password.getBytes(Charsets.ISO_8859_1), user,owner,permissions, id,
encRevision, length, encryptMetadata);
}