Package org.apache.poi

Examples of org.apache.poi.EncryptedDocumentException


        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

            is = new ByteArrayInputStream(descriptor.getBytes());
            keyData = DocumentBuilderFactory.newInstance()
                .newDocumentBuilder().parse(is)
                .getElementsByTagName("keyData").item(0).getAttributes();
        } catch (Exception e) {
            throw new EncryptedDocumentException("Unable to parse keyData");
        }

        keySize = Integer.parseInt(keyData.getNamedItem("keyBits")
                                   .getNodeValue());
        flags = 0;
        sizeExtra = 0;
        cspName = null;

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

        if ("AES".equals(cipher)) {
            providerType = PROVIDER_AES;
            if (blockSize == 16)
                algorithm = ALGORITHM_AES_128;
            else if (blockSize == 24)
                algorithm = ALGORITHM_AES_192;
            else if (blockSize == 32)
                algorithm = ALGORITHM_AES_256;
            else
                throw new EncryptedDocumentException("Unsupported key length");
        } else {
            throw new EncryptedDocumentException("Unsupported cipher");
        }

        String chaining = keyData.getNamedItem("cipherChaining").getNodeValue();

        if ("ChainingModeCBC".equals(chaining))
            cipherMode = MODE_CBC;
        else if ("ChainingModeCFB".equals(chaining))
            cipherMode = MODE_CFB;
        else
            throw new EncryptedDocumentException("Unsupported chaining mode");

        String hashAlg = keyData.getNamedItem("hashAlgorithm").getNodeValue();
        int hashSize = Integer.parseInt(keyData.getNamedItem("hashSize")
                                        .getNodeValue());

        if ("SHA1".equals(hashAlg) && hashSize == 20)
            hashAlgorithm = HASH_SHA1;
        else
            throw new EncryptedDocumentException("Unsupported hash algorithm");

        String salt = keyData.getNamedItem("saltValue").getNodeValue();
        int saltLength = Integer.parseInt(keyData.getNamedItem("saltSize")
                                          .getNodeValue());
        keySalt = Base64.decodeBase64(salt.getBytes());
        if (keySalt.length != saltLength)
            throw new EncryptedDocumentException("Invalid salt length");
    }
View Full Code Here

            while (len > 0) {
                if (_chunk == null) {
                    try {
                        _chunk = nextChunk();
                    } catch (GeneralSecurityException e) {
                        throw new EncryptedDocumentException(e.getMessage());
                    }
                }
                int count = (int)(4096L - (_pos & 0xfff));
                count = Math.min(available(), Math.min(count, len));
                System.arraycopy(_chunk, (int)(_pos & 0xfff), b, off, count);
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

            digestInfoValueBuf.write(digest);
            byte[] digestInfoValue = digestInfoValueBuf.toByteArray();
            byte[] signatureValue = cipher.doFinal(digestInfoValue);
            return signatureValue;
        } catch (Exception e) {
            throw new EncryptedDocumentException(e);
        }
    }
View Full Code Here

     * is initialized, which are necessary for validation. If false,
     * also the other properties needed for signing are been taken care of
     */
    protected void init(boolean onlyValidation) {
        if (opcPackage == null) {
            throw new EncryptedDocumentException("opcPackage is null");
        }
        if (uriDereferencer == null) {
            uriDereferencer = new OOXMLURIDereferencer();
        }
        if (uriDereferencer instanceof SignatureConfigurable) {
View Full Code Here

            break;
        // case ripemd256: result = new byte[]
        //    { 0x30, 0x2b, 0x30, 0x07, 0x06, 0x05, 0x2b, 0x24
        //    , 0x03, 0x02, 0x03, 0x04, 0x20 };
        //    break;
        default: throw new EncryptedDocumentException("Hash algorithm "
            +getDigestAlgo()+" not supported for signing.");
        }
       
        return result;
    }
View Full Code Here

        case sha224: return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA224;
        case sha256: return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256;
        case sha384: return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA384;
        case sha512: return XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA512;
        case ripemd160: return XMLSignature.ALGO_ID_SIGNATURE_RSA_RIPEMD160;
        default: throw new EncryptedDocumentException("Hash algorithm "
            +getDigestAlgo()+" not supported for signing.");
        }
    }
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.