/** * Create the xor key for xor obfuscation, which is used to create the xor array (method 1) * * @see <a href="http://msdn.microsoft.com/en-us/library/dd924704.aspx">2.3.7.2 Binary Document XOR Array Initialization Method 1</a> * @see <a href="http://msdn.microsoft.com/en-us/library/dd905229.aspx">2.3.7.4 Binary Document Password Verifier Derivation Method 2</a> * * @param password the password * @return the xor key */ public static int createXorKey1(String password) { // the xor key for method 1 is part of the verifier for method 2 // so we simply chop it from there return createXorVerifier2(password) >>> 16; }
/** * This method generates the xored-hashed password for word documents < 2007. */ public static String xorHashPassword(String password) { int hashedPassword = createXorVerifier2(password); return String.format(Locale.ROOT, "%1$08X", hashedPassword); }
/** * Convenience function which returns the reversed xored-hashed password for further * processing in word documents 2007 and newer, which utilize a real hashing algorithm like sha1. */ public static String xorHashPasswordReversed(String password) { int hashedPassword = createXorVerifier2(password); return String.format(Locale.ROOT, "%1$02X%2$02X%3$02X%4$02X" , ( hashedPassword >>> 0 ) & 0xFF , ( hashedPassword >>> 8 ) & 0xFF , ( hashedPassword >>> 16 ) & 0xFF , ( hashedPassword >>> 24 ) & 0xFF ); }
/** * Create the xor key for xor obfuscation, which is used to create the xor array (method 1) * * @see <a href="http://msdn.microsoft.com/en-us/library/dd924704.aspx">2.3.7.2 Binary Document XOR Array Initialization Method 1</a> * @see <a href="http://msdn.microsoft.com/en-us/library/dd905229.aspx">2.3.7.4 Binary Document Password Verifier Derivation Method 2</a> * * @param password the password * @return the xor key */ public static int createXorKey1(String password) { // the xor key for method 1 is part of the verifier for method 2 // so we simply chop it from there return createXorVerifier2(password) >>> 16; }
/** * This method generates the xored-hashed password for word documents < 2007. */ public static String xorHashPassword(String password) { int hashedPassword = createXorVerifier2(password); return String.format(Locale.ROOT, "%1$08X", hashedPassword); }
/** * Convenience function which returns the reversed xored-hashed password for further * processing in word documents 2007 and newer, which utilize a real hashing algorithm like sha1. */ public static String xorHashPasswordReversed(String password) { int hashedPassword = createXorVerifier2(password); return String.format(Locale.ROOT, "%1$02X%2$02X%3$02X%4$02X" , ( hashedPassword >>> 0 ) & 0xFF , ( hashedPassword >>> 8 ) & 0xFF , ( hashedPassword >>> 16 ) & 0xFF , ( hashedPassword >>> 24 ) & 0xFF ); }