int permissions = encParameters.getPermissions();
int revision = encParameters.getRevision();
int length = encParameters.getLength()/8;
COSString id = (COSString)document.getDocumentID().getObject( 0 );
byte[] u = encParameters.getUserKey();
byte[] o = encParameters.getOwnerKey();
boolean isUserPassword =
encryption.isUserPassword( password.getBytes(), u,
o, permissions, id.getBytes(), revision, length );
boolean isOwnerPassword =
encryption.isOwnerPassword( password.getBytes(), u,
o, permissions, id.getBytes(), revision, length );
if( isUserPassword )
{
encryptionKey =
encryption.computeEncryptedKey(
password.getBytes(), o,
permissions, id.getBytes(), revision, length );
}
else if( isOwnerPassword )
{
byte[] computedUserPassword =
encryption.getUserPassword(
password.getBytes(),
o,
revision,
length );
encryptionKey =
encryption.computeEncryptedKey(
computedUserPassword, o,
permissions, id.getBytes(), revision, length );
}
else
{
throw new InvalidPasswordException( "Error: The supplied password does not match " +
"either the owner or user password in the document." );