Search in sources :

Example 1 with EncryptionRecord

use of org.apache.poi.poifs.crypt.standard.EncryptionRecord in project poi by apache.

the class CryptoAPIEncryptor method createEncryptionInfoEntry.

protected void createEncryptionInfoEntry(DirectoryNode dir) throws IOException {
    DataSpaceMapUtils.addDefaultDataSpace(dir);
    final EncryptionInfo info = getEncryptionInfo();
    final CryptoAPIEncryptionHeader header = (CryptoAPIEncryptionHeader) getEncryptionInfo().getHeader();
    final CryptoAPIEncryptionVerifier verifier = (CryptoAPIEncryptionVerifier) getEncryptionInfo().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)

Example 2 with EncryptionRecord

use of org.apache.poi.poifs.crypt.standard.EncryptionRecord 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 3 with EncryptionRecord

use of org.apache.poi.poifs.crypt.standard.EncryptionRecord 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)3 EncryptionRecord (org.apache.poi.poifs.crypt.standard.EncryptionRecord)3 LittleEndianByteArrayOutputStream (org.apache.poi.util.LittleEndianByteArrayOutputStream)3 EncryptionDocument (com.microsoft.schemas.office.x2006.encryption.EncryptionDocument)1