Package org.apache.poi

Examples of org.apache.poi.EncryptedDocumentException


    // Create our FIB, and check for the doc being encrypted
    _fib = new FileInformationBlock(_mainStream);
    _cpSplit = new CPSplitCalculator(_fib);
    if(_fib.isFEncrypted()) {
      throw new EncryptedDocumentException("Cannot process encrypted word files!");
    }

    // use the fib to determine the name of the table stream.
    String name = "0Table";
    if (_fib.isFWhichTblStm())
View Full Code Here


        if (major == 4 && minor == 4)
            return new AgileDecryptor(info);
        else if (minor == 2 && (major == 3 || major == 4))
            return new EcmaDecryptor(info);
        else
            throw new EncryptedDocumentException("Unsupported version");
    }
View Full Code Here

        switch (algorithm) {
        case EncryptionHeader.ALGORITHM_AES_128: return 16;
        case EncryptionHeader.ALGORITHM_AES_192: return 24;
        case EncryptionHeader.ALGORITHM_AES_256: return 32;
        }
        throw new EncryptedDocumentException("Unknown block size");
    }
View Full Code Here

        MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
        byte[] bytes;
        try {
            bytes = password.getBytes("UTF-16LE");
        } catch (UnsupportedEncodingException e) {
            throw new EncryptedDocumentException("UTF16 not supported");
        }

        sha1.update(info.getVerifier().getSalt());
        byte[] hash = sha1.digest(bytes);
        byte[] iterator = new byte[4];
View Full Code Here

        key = Biff8EncryptionKey.create(fpr.getDocId());
      } else {
        key = Biff8EncryptionKey.create(userPassword, fpr.getDocId());
      }
      if (!key.validate(fpr.getSaltData(), fpr.getSaltHash())) {
        throw new EncryptedDocumentException(
            (userPassword == null ? "Default" : "Supplied")
            + " password is invalid for docId/saltData/saltHash");
      }
      return new RecordInputStream(original, key, _initialRecordsSize);
    }
View Full Code Here

    directory.createDocumentInputStream("WordDocument").read(_mainStream);

    // Create our FIB, and check for the doc being encrypted
    _fib = new FileInformationBlock(_mainStream);
    if(_fib.isFEncrypted()) {
      throw new EncryptedDocumentException("Cannot process encrypted word files!");
    }
  }
View Full Code Here

        offset = FibBase.getSize();
        assert offset == 32;

        if ( _fibBase.isFEncrypted() )
        {
            throw new EncryptedDocumentException(
                    "Cannot process encrypted word file" );
        }

        _csw = LittleEndian.getUShort( mainDocument, offset );
        offset += LittleEndian.SHORT_SIZE;
View Full Code Here

    directory.createDocumentInputStream("WordDocument").read(_mainStream);

    // Create our FIB, and check for the doc being encrypted
    _fib = new FileInformationBlock(_mainStream);
    if(_fib.isFEncrypted()) {
      throw new EncryptedDocumentException("Cannot process encrypted word files!");
    }
  }
View Full Code Here

    // Create our FIB, and check for the doc being encrypted
    _fib = new FileInformationBlock(_mainStream);
    _cpSplit = new CPSplitCalculator(_fib);
    if(_fib.isFEncrypted()) {
      throw new EncryptedDocumentException("Cannot process encrypted word files!");
    }

    // use the fib to determine the name of the table stream.
    String name = "0Table";
    if (_fib.isFWhichTblStm())
View Full Code Here

                    keyData = node.getAttributes();
                    break;
                }
            }
            if (keyData == null)
                throw new EncryptedDocumentException("");
        } catch (Exception e) {
            throw new EncryptedDocumentException("Unable to parse keyEncryptor");
        }

        spinCount = Integer.parseInt(keyData.getNamedItem("spinCount")
                                     .getNodeValue());
        verifier = Base64.decodeBase64(keyData
                                       .getNamedItem("encryptedVerifierHashInput")
                                       .getNodeValue().getBytes());
        salt = Base64.decodeBase64(keyData.getNamedItem("saltValue")
                                   .getNodeValue().getBytes());

        encryptedKey = Base64.decodeBase64(keyData
                                           .getNamedItem("encryptedKeyValue")
                                           .getNodeValue().getBytes());

        int saltSize = Integer.parseInt(keyData.getNamedItem("saltSize")
                                        .getNodeValue());
        if (saltSize != salt.length)
            throw new EncryptedDocumentException("Invalid salt size");

        verifierHash = Base64.decodeBase64(keyData
                                           .getNamedItem("encryptedVerifierHashValue")
                                           .getNodeValue().getBytes());

        int blockSize = Integer.parseInt(keyData.getNamedItem("blockSize")
                                         .getNodeValue());

        String alg = keyData.getNamedItem("cipherAlgorithm").getNodeValue();

        if ("AES".equals(alg)) {
            if (blockSize == 16)
                algorithm = EncryptionHeader.ALGORITHM_AES_128;
            else if (blockSize == 24)
                algorithm = EncryptionHeader.ALGORITHM_AES_192;
            else if (blockSize == 32)
                algorithm = EncryptionHeader.ALGORITHM_AES_256;
            else
                throw new EncryptedDocumentException("Unsupported block size");
        } else {
            throw new EncryptedDocumentException("Unsupported cipher");
        }

        String chain = keyData.getNamedItem("cipherChaining").getNodeValue();
        if ("ChainingModeCBC".equals(chain))
            cipherMode = EncryptionHeader.MODE_CBC;
        else if ("ChainingModeCFB".equals(chain))
            cipherMode = EncryptionHeader.MODE_CFB;
        else
            throw new EncryptedDocumentException("Unsupported chaining mode");

        verifierHashSize = Integer.parseInt(keyData.getNamedItem("hashSize")
                                            .getNodeValue());
    }
View Full Code Here

TOP

Related Classes of org.apache.poi.EncryptedDocumentException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.