Search in sources :

Example 1 with ChainingMode

use of org.apache.poi.poifs.crypt.ChainingMode in project poi by apache.

the class StandardDecryptor method getCipher.

private Cipher getCipher(SecretKey key) {
    EncryptionHeader em = getEncryptionInfo().getHeader();
    ChainingMode cm = em.getChainingMode();
    assert (cm == ChainingMode.ecb);
    return CryptoFunctions.getCipher(key, em.getCipherAlgorithm(), cm, null, Cipher.DECRYPT_MODE);
}
Also used : ChainingMode(org.apache.poi.poifs.crypt.ChainingMode) EncryptionHeader(org.apache.poi.poifs.crypt.EncryptionHeader)

Example 2 with ChainingMode

use of org.apache.poi.poifs.crypt.ChainingMode in project poi by apache.

the class AgileDecryptor method hashInput.

/* package */
static byte[] hashInput(AgileEncryptionVerifier ver, byte[] pwHash, byte[] blockKey, byte[] inputKey, int cipherMode) {
    CipherAlgorithm cipherAlgo = ver.getCipherAlgorithm();
    ChainingMode chainMode = ver.getChainingMode();
    int keySize = ver.getKeySize() / 8;
    int blockSize = ver.getBlockSize();
    HashAlgorithm hashAlgo = ver.getHashAlgorithm();
    byte[] intermedKey = generateKey(pwHash, hashAlgo, blockKey, keySize);
    SecretKey skey = new SecretKeySpec(intermedKey, cipherAlgo.jceId);
    byte[] iv = generateIv(hashAlgo, ver.getSalt(), null, blockSize);
    Cipher cipher = getCipher(skey, cipherAlgo, chainMode, iv, cipherMode);
    byte[] hashFinal;
    try {
        inputKey = getBlock0(inputKey, getNextBlockSize(inputKey.length, blockSize));
        hashFinal = cipher.doFinal(inputKey);
        return hashFinal;
    } catch (GeneralSecurityException e) {
        throw new EncryptedDocumentException(e);
    }
}
Also used : CipherAlgorithm(org.apache.poi.poifs.crypt.CipherAlgorithm) SecretKey(javax.crypto.SecretKey) EncryptedDocumentException(org.apache.poi.EncryptedDocumentException) ChainingMode(org.apache.poi.poifs.crypt.ChainingMode) SecretKeySpec(javax.crypto.spec.SecretKeySpec) GeneralSecurityException(java.security.GeneralSecurityException) Cipher(javax.crypto.Cipher) CryptoFunctions.getCipher(org.apache.poi.poifs.crypt.CryptoFunctions.getCipher) HashAlgorithm(org.apache.poi.poifs.crypt.HashAlgorithm)

Aggregations

ChainingMode (org.apache.poi.poifs.crypt.ChainingMode)2 GeneralSecurityException (java.security.GeneralSecurityException)1 Cipher (javax.crypto.Cipher)1 SecretKey (javax.crypto.SecretKey)1 SecretKeySpec (javax.crypto.spec.SecretKeySpec)1 EncryptedDocumentException (org.apache.poi.EncryptedDocumentException)1 CipherAlgorithm (org.apache.poi.poifs.crypt.CipherAlgorithm)1 CryptoFunctions.getCipher (org.apache.poi.poifs.crypt.CryptoFunctions.getCipher)1 EncryptionHeader (org.apache.poi.poifs.crypt.EncryptionHeader)1 HashAlgorithm (org.apache.poi.poifs.crypt.HashAlgorithm)1