Package org.apache.poi

Examples of org.apache.poi.EncryptedDocumentException


            os.write(buf);
            if (buf.length%4==2) {
                os.writeShort(0);
            }
        } catch (UnsupportedEncodingException e) {
            throw new EncryptedDocumentException(e);
        }
    }
View Full Code Here


            }
        }
        try {
            return new String(data, 0, data.length, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new EncryptedDocumentException(e);
        }
    }
View Full Code Here

                    for (int i=0; i<(4-scratchBytes); i++) {
                        os.writeByte(0);
                    }
                }
            } catch (UnsupportedEncodingException e) {
                throw new EncryptedDocumentException(e);
            }
        }       
    }
View Full Code Here

                return true;
            } else {
                return false;
            }
        } catch (GeneralSecurityException e) {
            throw new EncryptedDocumentException(e);
        }
    }
View Full Code Here

        try {
            MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
            return sha1.digest(buff);
        } catch (NoSuchAlgorithmException e) {
            throw new EncryptedDocumentException("hash algo not supported", e);
        }
    }
View Full Code Here

    public AgileEncryptionVerifier(String descriptor) {
        EncryptionDocument ed;
        try {
            ed = EncryptionDocument.Factory.parse(descriptor);
        } catch (XmlException e) {
            throw new EncryptedDocumentException("Unable to parse encryption descriptor", e);
        }

        Iterator<CTKeyEncryptor> encList = ed.getEncryption().getKeyEncryptors().getKeyEncryptorList().iterator();
        CTPasswordKeyEncryptor keyData;
        try {
            keyData = encList.next().getEncryptedPasswordKey();
            if (keyData == null) {
                throw new NullPointerException("encryptedKey not set");
            }
        } catch (Exception e) {
            throw new EncryptedDocumentException("Unable to parse keyData", e);
        }
       
        int keyBits = (int)keyData.getKeyBits();
       
        CipherAlgorithm ca = CipherAlgorithm.fromXmlId(keyData.getCipherAlgorithm().toString(), keyBits);
        setCipherAlgorithm(ca);

        int hashSize = keyData.getHashSize();

        HashAlgorithm ha = HashAlgorithm.fromEcmaId(keyData.getHashAlgorithm().toString());
        setHashAlgorithm(ha);

        if (getHashAlgorithm().hashSize != hashSize) {
            throw new EncryptedDocumentException("Unsupported hash algorithm: " +
                    keyData.getHashAlgorithm() + " @ " + hashSize + " bytes");
        }

        setSpinCount(keyData.getSpinCount());
        setEncryptedVerifier(keyData.getEncryptedVerifierHashInput());
        setSalt(keyData.getSaltValue());
        setEncryptedKey(keyData.getEncryptedKeyValue());
        setEncryptedVerifierHash(keyData.getEncryptedVerifierHashValue());

        int saltSize = keyData.getSaltSize();
        if (saltSize != getSalt().length)
            throw new EncryptedDocumentException("Invalid salt size");
       
        switch (keyData.getCipherChaining().intValue()) {
            case STCipherChaining.INT_CHAINING_MODE_CBC:
                setChainingMode(ChainingMode.cbc);
                break;
            case STCipherChaining.INT_CHAINING_MODE_CFB:
                setChainingMode(ChainingMode.cfb);
                break;
            default:
                throw new EncryptedDocumentException("Unsupported chaining mode - "+keyData.getCipherChaining().toString());
        }
       
        if (!encList.hasNext()) return;
       
        try {
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            while (encList.hasNext()) {
                CTCertificateKeyEncryptor certKey = encList.next().getEncryptedCertificateKey();
                AgileCertificateEntry ace = new AgileCertificateEntry();
                ace.certVerifier = certKey.getCertVerifier();
                ace.encryptedKey = certKey.getEncryptedKeyValue();
                ace.x509 = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(certKey.getX509Certificate()));
                certList.add(ace);
            }
        } catch (GeneralSecurityException e) {
            throw new EncryptedDocumentException("can't parse X509 certificate", e);
        }
    }
View Full Code Here

        setSpinCount(100000); // TODO: use parameter
    }
   
    protected void setSalt(byte salt[]) {
        if (salt == null || salt.length != getCipherAlgorithm().blockSize) {
            throw new EncryptedDocumentException("invalid verifier salt");
        }
        super.setSalt(salt);
    }
View Full Code Here

      }
     
        try {
            _rc4.update(data, offset, bytesToRead, data, offset);
        } catch (ShortBufferException e) {
            throw new EncryptedDocumentException("input buffer too small", e);
        }
  }
View Full Code Here

        try {
            rc4.update(verifierPrime, 0, verifierPrime.length, verifierPrime);
            rc4.update(verifierHashPrime, 0, verifierHashPrime.length, verifierHashPrime);
        } catch (ShortBufferException e) {
            throw new EncryptedDocumentException("buffer too short", e);
        }

        MessageDigest md5 = CryptoFunctions.getMessageDigest(HashAlgorithm.md5);
        md5.update(verifierPrime);
        byte[] finalVerifierResult = md5.digest();
View Full Code Here

        SecretKeySpec skeySpec = new SecretKeySpec(md5.digest(), _secretKey.getAlgorithm());
        try {
            rc4.init(Cipher.ENCRYPT_MODE, skeySpec);
        } catch (GeneralSecurityException e) {
            throw new EncryptedDocumentException("Can't rekey for next block", e);
        }
    }
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.