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);
}
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);
}
}
Aggregations