Search in sources :

Example 11 with EncryptionInfo

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);
}
Also used : LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream) EncryptionInfo(org.apache.poi.poifs.crypt.EncryptionInfo) EncryptionDocument(com.microsoft.schemas.office.x2006.encryption.EncryptionDocument) EncryptionRecord(org.apache.poi.poifs.crypt.standard.EncryptionRecord)

Example 12 with EncryptionInfo

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();
}
Also used : EncryptionInfo(org.apache.poi.poifs.crypt.EncryptionInfo)

Example 13 with EncryptionInfo

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);
    }
}
Also used : DocumentEncryptionAtom(org.apache.poi.hslf.record.DocumentEncryptionAtom) EncryptionInfo(org.apache.poi.poifs.crypt.EncryptionInfo)

Example 14 with EncryptionInfo

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();
}
Also used : EncryptionInfo(org.apache.poi.poifs.crypt.EncryptionInfo)

Example 15 with EncryptionInfo

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);
}
Also used : LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream) EncryptionInfo(org.apache.poi.poifs.crypt.EncryptionInfo) EncryptionRecord(org.apache.poi.poifs.crypt.standard.EncryptionRecord)

Aggregations

EncryptionInfo (org.apache.poi.poifs.crypt.EncryptionInfo)20 Decryptor (org.apache.poi.poifs.crypt.Decryptor)7 Test (org.junit.Test)5 File (java.io.File)4 OPCPackage (org.apache.poi.openxml4j.opc.OPCPackage)4 Encryptor (org.apache.poi.poifs.crypt.Encryptor)4 NPOIFSFileSystem (org.apache.poi.poifs.filesystem.NPOIFSFileSystem)4 LittleEndianByteArrayOutputStream (org.apache.poi.util.LittleEndianByteArrayOutputStream)4 FileOutputStream (java.io.FileOutputStream)3 InputStream (java.io.InputStream)3 GeneralSecurityException (java.security.GeneralSecurityException)3 SecretKey (javax.crypto.SecretKey)3 EncryptionRecord (org.apache.poi.poifs.crypt.standard.EncryptionRecord)3 POIFSFileSystem (org.apache.poi.poifs.filesystem.POIFSFileSystem)3 OutputStream (java.io.OutputStream)2 ZipFile (java.util.zip.ZipFile)2 EncryptedDocumentException (org.apache.poi.EncryptedDocumentException)2 TempFile (org.apache.poi.util.TempFile)2 XWPFWordExtractor (org.apache.poi.xwpf.extractor.XWPFWordExtractor)2 XWPFDocument (org.apache.poi.xwpf.usermodel.XWPFDocument)2