use of org.apache.poi.poifs.crypt.EncryptionInfo in project poi by apache.
the class AgileEncryptor method createEncryptionInfoEntry.
protected void createEncryptionInfoEntry(DirectoryNode dir, File tmpFile) throws IOException, GeneralSecurityException {
DataSpaceMapUtils.addDefaultDataSpace(dir);
final EncryptionInfo info = getEncryptionInfo();
EncryptionRecord er = new EncryptionRecord() {
@Override
public void write(LittleEndianByteArrayOutputStream bos) {
// EncryptionVersionInfo (4 bytes): A Version structure (section 2.1.4), where
// Version.vMajor MUST be 0x0004 and Version.vMinor MUST be 0x0004
bos.writeShort(info.getVersionMajor());
bos.writeShort(info.getVersionMinor());
// Reserved (4 bytes): A value that MUST be 0x00000040
bos.writeInt(info.getEncryptionFlags());
EncryptionDocument ed = createEncryptionDocument();
marshallEncryptionDocument(ed, bos);
}
};
createEncryptionEntry(dir, "EncryptionInfo", er);
}
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();
}
use of org.apache.poi.poifs.crypt.EncryptionInfo in project poi by apache.
the class BinaryRC4Encryptor method createEncryptionInfoEntry.
protected void createEncryptionInfoEntry(DirectoryNode dir) throws IOException {
DataSpaceMapUtils.addDefaultDataSpace(dir);
final EncryptionInfo info = getEncryptionInfo();
final BinaryRC4EncryptionHeader header = (BinaryRC4EncryptionHeader) info.getHeader();
final BinaryRC4EncryptionVerifier verifier = (BinaryRC4EncryptionVerifier) info.getVerifier();
EncryptionRecord er = new EncryptionRecord() {
@Override
public void write(LittleEndianByteArrayOutputStream bos) {
bos.writeShort(info.getVersionMajor());
bos.writeShort(info.getVersionMinor());
header.write(bos);
verifier.write(bos);
}
};
DataSpaceMapUtils.createEncryptionEntry(dir, "EncryptionInfo", er);
}
Aggregations