Search in sources :

Example 1 with LittleEndianByteArrayOutputStream

use of org.apache.poi.util.LittleEndianByteArrayOutputStream in project poi by apache.

the class FilePassRecord method serialize.

@SuppressWarnings("resource")
@Override
public void serialize(LittleEndianOutput out) {
    out.writeShort(encryptionType);
    byte[] data = new byte[1024];
    // NOSONAR
    LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(data, 0);
    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());
}
Also used : CryptoAPIEncryptionVerifier(org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionVerifier) LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream) EncryptedDocumentException(org.apache.poi.EncryptedDocumentException) CryptoAPIEncryptionHeader(org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionHeader) XOREncryptionHeader(org.apache.poi.poifs.crypt.xor.XOREncryptionHeader) BinaryRC4EncryptionVerifier(org.apache.poi.poifs.crypt.binaryrc4.BinaryRC4EncryptionVerifier) XOREncryptionVerifier(org.apache.poi.poifs.crypt.xor.XOREncryptionVerifier) BinaryRC4EncryptionHeader(org.apache.poi.poifs.crypt.binaryrc4.BinaryRC4EncryptionHeader)

Example 2 with LittleEndianByteArrayOutputStream

use of org.apache.poi.util.LittleEndianByteArrayOutputStream in project poi by apache.

the class Ptg method serializePtgs.

/**
	 * Writes the ptgs to the data buffer, starting at the specified offset.
	 *
	 * <br/>
	 * The 2 byte encode length field is <b>not</b> written by this method.
	 * @return number of bytes written
	 */
public static int serializePtgs(Ptg[] ptgs, byte[] array, int offset) {
    // NOSONAR
    LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(array, offset);
    List<Ptg> arrayPtgs = null;
    for (Ptg ptg : ptgs) {
        ptg.write(out);
        if (ptg instanceof ArrayPtg) {
            if (arrayPtgs == null) {
                arrayPtgs = new ArrayList<Ptg>(5);
            }
            arrayPtgs.add(ptg);
        }
    }
    if (arrayPtgs != null) {
        for (Ptg arrayPtg : arrayPtgs) {
            ArrayPtg p = (ArrayPtg) arrayPtg;
            p.writeTokenValueBytes(out);
        }
    }
    return out.getWriteIndex() - offset;
}
Also used : LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream)

Example 3 with LittleEndianByteArrayOutputStream

use of org.apache.poi.util.LittleEndianByteArrayOutputStream in project poi by apache.

the class CellRangeAddressList method serialize.

public int serialize(int offset, byte[] data) {
    int totalSize = getSize();
    serialize(new LittleEndianByteArrayOutputStream(data, offset, totalSize));
    return totalSize;
}
Also used : LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream)

Example 4 with LittleEndianByteArrayOutputStream

use of org.apache.poi.util.LittleEndianByteArrayOutputStream 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 5 with LittleEndianByteArrayOutputStream

use of org.apache.poi.util.LittleEndianByteArrayOutputStream in project poi by apache.

the class ObjRecord method serialize.

@Override
public int serialize(int offset, byte[] data) {
    int recSize = getRecordSize();
    int dataSize = recSize - 4;
    // NOSONAR
    LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(data, offset, recSize);
    out.writeShort(sid);
    out.writeShort(dataSize);
    if (_uninterpretedData == null) {
        for (int i = 0; i < subrecords.size(); i++) {
            SubRecord record = subrecords.get(i);
            record.serialize(out);
        }
        int expectedEndIx = offset + dataSize;
        // padding
        while (out.getWriteIndex() < expectedEndIx) {
            out.writeByte(0);
        }
    } else {
        out.write(_uninterpretedData);
    }
    return recSize;
}
Also used : LittleEndianByteArrayOutputStream(org.apache.poi.util.LittleEndianByteArrayOutputStream)

Aggregations

LittleEndianByteArrayOutputStream (org.apache.poi.util.LittleEndianByteArrayOutputStream)20 EncryptedDocumentException (org.apache.poi.EncryptedDocumentException)5 IOException (java.io.IOException)4 EncryptionInfo (org.apache.poi.poifs.crypt.EncryptionInfo)4 EncryptionRecord (org.apache.poi.poifs.crypt.standard.EncryptionRecord)3 Test (org.junit.Test)3 ChunkedCipherOutputStream (org.apache.poi.poifs.crypt.ChunkedCipherOutputStream)2 CryptoAPIEncryptionHeader (org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionHeader)2 CryptoAPIEncryptionVerifier (org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionVerifier)2 LittleEndianByteArrayInputStream (org.apache.poi.util.LittleEndianByteArrayInputStream)2 EncryptionDocument (com.microsoft.schemas.office.x2006.encryption.EncryptionDocument)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 HashMap (java.util.HashMap)1 NoSuchElementException (java.util.NoSuchElementException)1 AssertionFailedError (junit.framework.AssertionFailedError)1 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)1 EscherBlipRecord (org.apache.poi.ddf.EscherBlipRecord)1 EscherRecord (org.apache.poi.ddf.EscherRecord)1