use of org.apache.poi.poifs.crypt.EncryptionInfo in project poi by apache.
the class TestDocumentEncryption method cryptoAPIChangeKeySize.
@Test
public void cryptoAPIChangeKeySize() throws Exception {
String pptFile = "cryptoapi-proc2356.ppt";
Biff8EncryptionKey.setCurrentUserPassword("crypto");
NPOIFSFileSystem fs = new NPOIFSFileSystem(slTests.getFile(pptFile), true);
HSLFSlideShowImpl hss = new HSLFSlideShowImpl(fs);
// need to cache data (i.e. read all data) before changing the key size
List<HSLFPictureData> picsExpected = hss.getPictureData();
hss.getDocumentSummaryInformation();
EncryptionInfo ei = hss.getDocumentEncryptionAtom().getEncryptionInfo();
((CryptoAPIEncryptionHeader) ei.getHeader()).setKeySize(0x78);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
hss.write(bos);
hss.close();
fs.close();
fs = new NPOIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
hss = new HSLFSlideShowImpl(fs);
List<HSLFPictureData> picsActual = hss.getPictureData();
assertEquals(picsExpected.size(), picsActual.size());
for (int i = 0; i < picsExpected.size(); i++) {
assertArrayEquals(picsExpected.get(i).getRawData(), picsActual.get(i).getRawData());
}
hss.close();
fs.close();
}
use of org.apache.poi.poifs.crypt.EncryptionInfo in project poi by apache.
the class TestBinaryRC4 method confirmValid.
private static void confirmValid(boolean expectedResult, String docIdHex, String saltDataHex, String saltHashHex, String password) throws GeneralSecurityException {
byte[] docId = readFromString(docIdHex);
byte[] saltData = readFromString(saltDataHex);
byte[] saltHash = readFromString(saltHashHex);
EncryptionInfo ei = new EncryptionInfo(EncryptionMode.binaryRC4);
BinaryRC4EncryptionVerifier ver = (BinaryRC4EncryptionVerifier) ei.getVerifier();
ver.setSalt(docId);
ver.setEncryptedVerifier(saltData);
ver.setEncryptedVerifierHash(saltHash);
String pass = password == null ? Decryptor.DEFAULT_PASSWORD : password;
boolean actResult = ei.getDecryptor().verifyPassword(pass);
if (expectedResult) {
assertTrue("validate failed", actResult);
} else {
assertFalse("validate succeeded unexpectedly", actResult);
}
}
use of org.apache.poi.poifs.crypt.EncryptionInfo in project poi by apache.
the class HSLFSlideShowEncrypted method decryptInit.
protected void decryptInit() {
if (dec != null) {
return;
}
EncryptionInfo ei = dea.getEncryptionInfo();
dec = (CryptoAPIDecryptor) ei.getDecryptor();
}
use of org.apache.poi.poifs.crypt.EncryptionInfo in project poi by apache.
the class HSLFSlideShowEncrypted method updateEncryptionRecord.
protected Record[] updateEncryptionRecord(Record[] records) {
String password = Biff8EncryptionKey.getCurrentUserPassword();
if (password == null) {
if (dea == null) {
// no password given, no encryption record exits -> done
return records;
} else {
// need to remove password data
dea = null;
return removeEncryptionRecord(records);
}
} else {
// create password record
if (dea == null) {
dea = new DocumentEncryptionAtom();
enc = null;
}
encryptInit();
EncryptionInfo ei = dea.getEncryptionInfo();
byte[] salt = ei.getVerifier().getSalt();
if (salt == null) {
enc.confirmPassword(password);
} else {
byte[] verifier = ei.getDecryptor().getVerifier();
enc.confirmPassword(password, null, null, verifier, salt, null);
}
// move EncryptionRecord to last slide position
records = normalizeRecords(records);
return addEncryptionRecord(records, dea);
}
}
use of org.apache.poi.poifs.crypt.EncryptionInfo in project poi by apache.
the class HSLFSlideShowEncrypted method encryptInit.
protected void encryptInit() {
if (enc != null) {
return;
}
EncryptionInfo ei = dea.getEncryptionInfo();
enc = (CryptoAPIEncryptor) ei.getEncryptor();
}
Aggregations