@Override public void write(LittleEndianByteArrayOutputStream bos) { bos.write(getEncryptedKey()); bos.write(getEncryptedVerifier()); }
protected XOREncryptionVerifier() { setEncryptedKey(new byte[2]); setEncryptedVerifier(new byte[2]); }
@Override public void initialize(EncryptionInfo info, LittleEndianInput dis) throws IOException { info.setHeader(new XOREncryptionHeader()); info.setVerifier(new XOREncryptionVerifier(dis)); Decryptor dec = new XORDecryptor(); dec.setEncryptionInfo(info); info.setDecryptor(dec); Encryptor enc = new XOREncryptor(); enc.setEncryptionInfo(info); info.setEncryptor(enc); }
@SuppressWarnings("resource") @Override public void serialize(LittleEndianOutput out) { out.writeShort(encryptionType); byte data[] = new byte[1024]; LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(data, 0); // NOSONAR switch (encryptionInfo.getEncryptionMode()) { case xor: ((XOREncryptionHeader)encryptionInfo.getHeader()).write(bos); ((XOREncryptionVerifier)encryptionInfo.getVerifier()).write(bos); break; case binaryRC4: out.writeShort(encryptionInfo.getVersionMajor()); out.writeShort(encryptionInfo.getVersionMinor()); ((BinaryRC4EncryptionHeader)encryptionInfo.getHeader()).write(bos); ((BinaryRC4EncryptionVerifier)encryptionInfo.getVerifier()).write(bos); break; case cryptoAPI: out.writeShort(encryptionInfo.getVersionMajor()); out.writeShort(encryptionInfo.getVersionMinor()); out.writeInt(encryptionInfo.getEncryptionFlags()); ((CryptoAPIEncryptionHeader)encryptionInfo.getHeader()).write(bos); ((CryptoAPIEncryptionVerifier)encryptionInfo.getVerifier()).write(bos); break; default: throw new EncryptedDocumentException("not supported"); } out.write(data, 0, bos.getWriteIndex()); }
@Override public void initialize(EncryptionInfo info, CipherAlgorithm cipherAlgorithm, HashAlgorithm hashAlgorithm, int keyBits, int blockSize, ChainingMode chainingMode) { info.setHeader(new XOREncryptionHeader()); info.setVerifier(new XOREncryptionVerifier()); Decryptor dec = new XORDecryptor(); dec.setEncryptionInfo(info); info.setDecryptor(dec); Encryptor enc = new XOREncryptor(); enc.setEncryptionInfo(info); info.setEncryptor(enc); } }
@SuppressWarnings("resource") @Override public void serialize(LittleEndianOutput out) { out.writeShort(encryptionType); byte data[] = new byte[1024]; LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(data, 0); // NOSONAR switch (encryptionInfo.getEncryptionMode()) { case xor: ((XOREncryptionHeader)encryptionInfo.getHeader()).write(bos); ((XOREncryptionVerifier)encryptionInfo.getVerifier()).write(bos); break; case binaryRC4: out.writeShort(encryptionInfo.getVersionMajor()); out.writeShort(encryptionInfo.getVersionMinor()); ((BinaryRC4EncryptionHeader)encryptionInfo.getHeader()).write(bos); ((BinaryRC4EncryptionVerifier)encryptionInfo.getVerifier()).write(bos); break; case cryptoAPI: out.writeShort(encryptionInfo.getVersionMajor()); out.writeShort(encryptionInfo.getVersionMinor()); out.writeInt(encryptionInfo.getEncryptionFlags()); ((CryptoAPIEncryptionHeader)encryptionInfo.getHeader()).write(bos); ((CryptoAPIEncryptionVerifier)encryptionInfo.getVerifier()).write(bos); break; default: throw new EncryptedDocumentException("not supported"); } out.write(data, 0, bos.getWriteIndex()); }
protected XOREncryptionVerifier(LittleEndianInput is) { /** * key (2 bytes): An unsigned integer that specifies the obfuscation key. * See [MS-OFFCRYPTO], 2.3.6.2 section, the first step of initializing XOR * array where it describes the generation of 16-bit XorKey value. */ byte key[] = new byte[2]; is.readFully(key); setEncryptedKey(key); /** * verificationBytes (2 bytes): An unsigned integer that specifies * the password verification identifier. */ byte verifier[] = new byte[2]; is.readFully(verifier); setEncryptedVerifier(verifier); }
@Override public boolean verifyPassword(String password) { XOREncryptionVerifier ver = (XOREncryptionVerifier)getEncryptionInfo().getVerifier(); int keyVer = LittleEndian.getUShort(ver.getEncryptedKey()); int verifierVer = LittleEndian.getUShort(ver.getEncryptedVerifier()); int keyComp = CryptoFunctions.createXorKey1(password); int verifierComp = CryptoFunctions.createXorVerifier1(password); if (keyVer == keyComp && verifierVer == verifierComp) { byte xorArray[] = CryptoFunctions.createXorArray1(password); setSecretKey(new SecretKeySpec(xorArray, "XOR")); return true; } else { return false; } }
@Override public void initialize(EncryptionInfo info, LittleEndianInput dis) throws IOException { info.setHeader(new XOREncryptionHeader()); info.setVerifier(new XOREncryptionVerifier(dis)); Decryptor dec = new XORDecryptor(); dec.setEncryptionInfo(info); info.setDecryptor(dec); Encryptor enc = new XOREncryptor(); enc.setEncryptionInfo(info); info.setEncryptor(enc); }
@Override public void confirmPassword(String password) { int keyComp = CryptoFunctions.createXorKey1(password); int verifierComp = CryptoFunctions.createXorVerifier1(password); byte xorArray[] = CryptoFunctions.createXorArray1(password); byte shortBuf[] = new byte[2]; XOREncryptionVerifier ver = (XOREncryptionVerifier)getEncryptionInfo().getVerifier(); LittleEndian.putUShort(shortBuf, 0, keyComp); ver.setEncryptedKey(shortBuf); LittleEndian.putUShort(shortBuf, 0, verifierComp); ver.setEncryptedVerifier(shortBuf); setSecretKey(new SecretKeySpec(xorArray, "XOR")); }
@Override public void write(LittleEndianByteArrayOutputStream bos) { bos.write(getEncryptedKey()); bos.write(getEncryptedVerifier()); }
@Override public void initialize(EncryptionInfo info, CipherAlgorithm cipherAlgorithm, HashAlgorithm hashAlgorithm, int keyBits, int blockSize, ChainingMode chainingMode) { info.setHeader(new XOREncryptionHeader()); info.setVerifier(new XOREncryptionVerifier()); Decryptor dec = new XORDecryptor(); dec.setEncryptionInfo(info); info.setDecryptor(dec); Encryptor enc = new XOREncryptor(); enc.setEncryptionInfo(info); info.setEncryptor(enc); } }
protected XOREncryptionVerifier() { setEncryptedKey(new byte[2]); setEncryptedVerifier(new byte[2]); }
@Override public boolean verifyPassword(String password) { XOREncryptionVerifier ver = (XOREncryptionVerifier)getEncryptionInfo().getVerifier(); int keyVer = LittleEndian.getUShort(ver.getEncryptedKey()); int verifierVer = LittleEndian.getUShort(ver.getEncryptedVerifier()); int keyComp = CryptoFunctions.createXorKey1(password); int verifierComp = CryptoFunctions.createXorVerifier1(password); if (keyVer == keyComp && verifierVer == verifierComp) { byte xorArray[] = CryptoFunctions.createXorArray1(password); setSecretKey(new SecretKeySpec(xorArray, "XOR")); return true; } else { return false; } }
protected XOREncryptionVerifier(LittleEndianInput is) { /** * key (2 bytes): An unsigned integer that specifies the obfuscation key. * See [MS-OFFCRYPTO], 2.3.6.2 section, the first step of initializing XOR * array where it describes the generation of 16-bit XorKey value. */ byte key[] = new byte[2]; is.readFully(key); setEncryptedKey(key); /** * verificationBytes (2 bytes): An unsigned integer that specifies * the password verification identifier. */ byte verifier[] = new byte[2]; is.readFully(verifier); setEncryptedVerifier(verifier); }
@Override public void confirmPassword(String password) { int keyComp = CryptoFunctions.createXorKey1(password); int verifierComp = CryptoFunctions.createXorVerifier1(password); byte xorArray[] = CryptoFunctions.createXorArray1(password); byte shortBuf[] = new byte[2]; XOREncryptionVerifier ver = (XOREncryptionVerifier)getEncryptionInfo().getVerifier(); LittleEndian.putUShort(shortBuf, 0, keyComp); ver.setEncryptedKey(shortBuf); LittleEndian.putUShort(shortBuf, 0, verifierComp); ver.setEncryptedVerifier(shortBuf); setSecretKey(new SecretKeySpec(xorArray, "XOR")); }