setDecryptMetadata(encryption.isEncryptMetaData()); StandardDecryptionMaterial material = (StandardDecryptionMaterial)decryptionMaterial; byte[] documentIDBytes = getDocumentIDBytes(documentIDArray); if( isOwnerPassword(password.getBytes(passwordCharset), userKey, ownerKey, dicPermissions, documentIDBytes, dicRevision, dicLength, encryptMetadata) ) setCurrentAccessPermission(currentAccessPermission); computedPassword = getUserPassword(password.getBytes(passwordCharset), ownerKey, dicRevision, dicLength ); computeEncryptedKey( computedPassword, ownerKey, userKey, oe, ue, else if( isUserPassword(password.getBytes(passwordCharset), userKey, ownerKey, dicPermissions, documentIDBytes, dicRevision, dicLength, encryptMetadata) ) setCurrentAccessPermission(currentAccessPermission); computeEncryptedKey( password.getBytes(passwordCharset), ownerKey, userKey, oe, ue, validatePerms(encryption, dicPermissions, encryptMetadata);
return computeEncryptedKeyRev56(password, isOwnerPassword, o, u, oe, ue, encRevision); return computeEncryptedKeyRev234(password, o, permissions, id, encryptMetadata, keyLengthInBytes, encRevision);
byte[] truncatedOwnerPassword = truncate127(ownerPassword); if (encRevision == 5) hash = computeSHA256(truncatedOwnerPassword, oValidationSalt, user); hash = computeHash2A(truncatedOwnerPassword, oValidationSalt, user); byte[] userPassword = getUserPassword( ownerPassword, owner, encRevision, keyLengthInBytes ); return isUserPassword( userPassword, user, owner, permissions, id, encRevision, keyLengthInBytes, encryptMetadata );
private boolean isUserPassword56(byte[] password, byte[] user, int encRevision) throws IOException { byte[] truncatedPassword = truncate127(password); byte[] uHash = new byte[32]; byte[] uValidationSalt = new byte[8]; System.arraycopy(user, 0, uHash, 0, 32); System.arraycopy(user, 32, uValidationSalt, 0, 8); byte[] hash; if (encRevision == 5) { hash = computeSHA256(truncatedPassword, uValidationSalt, null); } else { hash = computeHash2A(truncatedPassword, uValidationSalt, null); } return Arrays.equals(hash, uHash); }
private byte[] computeHash2A(byte[] password, byte[] salt, byte[] u) throws IOException { byte[] userKey; if (u == null) { userKey = new byte[0]; } else if (u.length < 48) { throw new IOException("Bad U length"); } else if (u.length > 48) { // must truncate userKey = new byte[48]; System.arraycopy(u, 0, userKey, 0, 48); } else { userKey = u; } byte[] truncatedPassword = truncate127(password); byte[] input = concat(truncatedPassword, salt, userKey); return computeHash2B(input, truncatedPassword, userKey); }
byte[] userPasswordBytes = truncate127(userPassword.getBytes(Charsets.UTF_8)); byte[] userValidationSalt = new byte[8]; byte[] userKeySalt = new byte[8]; rnd.nextBytes(userValidationSalt); rnd.nextBytes(userKeySalt); byte[] hashU = computeHash2B(concat(userPasswordBytes, userValidationSalt), userPasswordBytes, null); byte[] u = concat(hashU, userValidationSalt, userKeySalt); byte[] hashUE = computeHash2B(concat(userPasswordBytes, userKeySalt), userPasswordBytes, null); cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(hashUE, "AES"), byte[] ownerPasswordBytes = truncate127(ownerPassword.getBytes(Charsets.UTF_8)); byte[] ownerValidationSalt = new byte[8]; byte[] ownerKeySalt = new byte[8]; rnd.nextBytes(ownerValidationSalt); rnd.nextBytes(ownerKeySalt); byte[] hashO = computeHash2B(concat(ownerPasswordBytes, ownerValidationSalt, u), ownerPasswordBytes, u); byte[] o = concat(hashO, ownerValidationSalt, ownerKeySalt); byte[] hashOE = computeHash2B(concat(ownerPasswordBytes, ownerKeySalt, u), ownerPasswordBytes, u); cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(hashOE, "AES"), prepareEncryptionDictAES(encryptionDictionary, COSName.AESV3); logIfStrongEncryptionMissing();
byte[] ownerBytes = computeOwnerPassword( ownerPassword.getBytes(Charsets.ISO_8859_1), userPassword.getBytes(Charsets.ISO_8859_1), revision, length); byte[] userBytes = computeUserPassword( userPassword.getBytes(Charsets.ISO_8859_1), ownerBytes, permissionInt, id.getBytes(), revision, length, true); encryptionKey = computeEncryptedKey(userPassword.getBytes(Charsets.ISO_8859_1), ownerBytes, null, null, null, permissionInt, id.getBytes(), revision, length, true, false); prepareEncryptionDictAES(encryptionDictionary, COSName.AESV2);
int version = computeVersionNumber(); int revision = computeRevisionNumber(version); encryptionDictionary.setFilter(FILTER); encryptionDictionary.setVersion(version); prepareEncryptionDictRev6(ownerPassword, userPassword, encryptionDictionary, permissionInt); prepareEncryptionDictRev2345(ownerPassword, userPassword, encryptionDictionary, permissionInt, document, revision, length);
byte[] rc4Key = computeRC4key(ownerPassword, encRevision, length); byte[] paddedUser = truncateOrPad( userPassword ); encryptDataRC4(rc4Key, new ByteArrayInputStream(paddedUser), encrypted); encryptDataRC4(iterationKey, input, encrypted );
hash = computeSHA256(password, oKeySalt, u); hash = computeHash2A(password, oKeySalt, u); hash = computeSHA256(password, uKeySalt, null); hash = computeHash2A(password, uKeySalt, null); logIfStrongEncryptionMissing(); throw new IOException(e);
byte[] rc4Key = computeRC4key(ownerPassword, encRevision, length); encryptDataRC4(rc4Key, owner, result); encryptDataRC4(iterationKey, otemp, result); otemp = result.toByteArray();
byte[] encKey = computeEncryptedKey( password, owner, null, null, null, permissions, id, encRevision, keyLengthInBytes, encryptMetadata, true ); encryptDataRC4(encKey, ENCRYPT_PADDING, result ); encryptDataRC4(iterationKey, input, result);
private boolean isUserPassword234(byte[] password, byte[] user, byte[] owner, int permissions, byte[] id, int encRevision, int length, boolean encryptMetadata) throws IOException { byte[] passwordBytes = computeUserPassword(password, owner, permissions, id, encRevision, length, encryptMetadata); if (encRevision == 2) { return Arrays.equals(user, passwordBytes); } else { // compare first 16 bytes only return Arrays.equals(Arrays.copyOf(user, 16), Arrays.copyOf(passwordBytes, 16)); } }
byte[] userPasswordBytes = truncate127(userPassword.getBytes(Charsets.UTF_8)); byte[] userValidationSalt = new byte[8]; byte[] userKeySalt = new byte[8]; rnd.nextBytes(userValidationSalt); rnd.nextBytes(userKeySalt); byte[] hashU = computeHash2B(concat(userPasswordBytes, userValidationSalt), userPasswordBytes, null); byte[] u = concat(hashU, userValidationSalt, userKeySalt); byte[] hashUE = computeHash2B(concat(userPasswordBytes, userKeySalt), userPasswordBytes, null); cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(hashUE, "AES"), byte[] ownerPasswordBytes = truncate127(ownerPassword.getBytes(Charsets.UTF_8)); byte[] ownerValidationSalt = new byte[8]; byte[] ownerKeySalt = new byte[8]; rnd.nextBytes(ownerValidationSalt); rnd.nextBytes(ownerKeySalt); byte[] hashO = computeHash2B(concat(ownerPasswordBytes, ownerValidationSalt, u), ownerPasswordBytes, u); byte[] o = concat(hashO, ownerValidationSalt, ownerKeySalt); byte[] hashOE = computeHash2B(concat(ownerPasswordBytes, ownerKeySalt, u), ownerPasswordBytes, u); cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(hashOE, "AES"), prepareEncryptionDictAES(encryptionDictionary, COSName.AESV3); logIfStrongEncryptionMissing();
byte[] ownerBytes = computeOwnerPassword( ownerPassword.getBytes(Charsets.ISO_8859_1), userPassword.getBytes(Charsets.ISO_8859_1), revision, length); byte[] userBytes = computeUserPassword( userPassword.getBytes(Charsets.ISO_8859_1), ownerBytes, permissionInt, id.getBytes(), revision, length, true); encryptionKey = computeEncryptedKey(userPassword.getBytes(Charsets.ISO_8859_1), ownerBytes, null, null, null, permissionInt, id.getBytes(), revision, length, true, false); prepareEncryptionDictAES(encryptionDictionary, COSName.AESV2);
int version = computeVersionNumber(); int revision = computeRevisionNumber(version); encryptionDictionary.setFilter(FILTER); encryptionDictionary.setVersion(version); prepareEncryptionDictRev6(ownerPassword, userPassword, encryptionDictionary, permissionInt); prepareEncryptionDictRev2345(ownerPassword, userPassword, encryptionDictionary, permissionInt, document, revision, length);
private boolean isUserPassword56(byte[] password, byte[] user, int encRevision) throws IOException { byte[] truncatedPassword = truncate127(password); byte[] uHash = new byte[32]; byte[] uValidationSalt = new byte[8]; System.arraycopy(user, 0, uHash, 0, 32); System.arraycopy(user, 32, uValidationSalt, 0, 8); byte[] hash; if (encRevision == 5) { hash = computeSHA256(truncatedPassword, uValidationSalt, null); } else { hash = computeHash2A(truncatedPassword, uValidationSalt, null); } return Arrays.equals(hash, uHash); }
private byte[] computeHash2A(byte[] password, byte[] salt, byte[] u) throws IOException { byte[] userKey; if (u == null) { userKey = new byte[0]; } else if (u.length < 48) { throw new IOException("Bad U length"); } else if (u.length > 48) { // must truncate userKey = new byte[48]; System.arraycopy(u, 0, userKey, 0, 48); } else { userKey = u; } byte[] truncatedPassword = truncate127(password); byte[] input = concat(truncatedPassword, salt, userKey); return computeHash2B(input, truncatedPassword, userKey); }
byte[] rc4Key = computeRC4key(ownerPassword, encRevision, length); byte[] paddedUser = truncateOrPad( userPassword ); encryptDataRC4(rc4Key, new ByteArrayInputStream(paddedUser), encrypted); encryptDataRC4(iterationKey, input, encrypted );
hash = computeSHA256(password, oKeySalt, u); hash = computeHash2A(password, oKeySalt, u); hash = computeSHA256(password, uKeySalt, null); hash = computeHash2A(password, uKeySalt, null); logIfStrongEncryptionMissing(); throw new IOException(e);