Search in sources :

Example 1 with BinaryRC4EncryptionVerifier

use of org.apache.poi.poifs.crypt.binaryrc4.BinaryRC4EncryptionVerifier 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)

Aggregations

EncryptedDocumentException (org.apache.poi.EncryptedDocumentException)1 BinaryRC4EncryptionHeader (org.apache.poi.poifs.crypt.binaryrc4.BinaryRC4EncryptionHeader)1 BinaryRC4EncryptionVerifier (org.apache.poi.poifs.crypt.binaryrc4.BinaryRC4EncryptionVerifier)1 CryptoAPIEncryptionHeader (org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionHeader)1 CryptoAPIEncryptionVerifier (org.apache.poi.poifs.crypt.cryptoapi.CryptoAPIEncryptionVerifier)1 XOREncryptionHeader (org.apache.poi.poifs.crypt.xor.XOREncryptionHeader)1 XOREncryptionVerifier (org.apache.poi.poifs.crypt.xor.XOREncryptionVerifier)1 LittleEndianByteArrayOutputStream (org.apache.poi.util.LittleEndianByteArrayOutputStream)1