JCEEncryptionHandlerState.java
3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityConfigurationException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.securityframework.EncryptionHandlerState
*/
package com.adobe.internal.pdftoolkit.core.encryption;
import com.adobe.internal.pdftoolkit.core.encryption.JCECipherEncryptionHandler;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityConfigurationException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.securityframework.EncryptionHandlerState;
import java.security.NoSuchAlgorithmException;
import java.security.Provider;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
public final class JCEEncryptionHandlerState
implements EncryptionHandlerState {
private JCECipherEncryptionHandler mParentHandler;
private boolean mInited;
private Cipher mCipher;
public JCEEncryptionHandlerState(JCECipherEncryptionHandler parent) throws PDFSecurityConfigurationException {
this.mParentHandler = parent;
this.mInited = false;
try {
this.mCipher = Cipher.getInstance(this.mParentHandler.mCipher.getAlgorithm(), this.mParentHandler.mCipher.getProvider());
}
catch (NoSuchAlgorithmException e) {
throw new PDFSecurityConfigurationException("Cannot instantiate Cipher object", (Throwable)e);
}
catch (NoSuchPaddingException e) {
throw new PDFSecurityConfigurationException("Cannot instantiate Cipher object", (Throwable)e);
}
}
public byte[] init(byte[] buffer, int start, int len, byte[] additionKey, int mode) throws PDFSecurityException {
byte[] mKey = this.mParentHandler.calculateCompleteKey(additionKey);
byte[] firstPart = this.mParentHandler.initCipher(this.mCipher, buffer, len, mKey, mode);
this.mInited = true;
return this.mCipher.update(firstPart);
}
public byte[] update(byte[] buffer, int start, int len) throws PDFSecurityException {
if (!this.mInited) {
throw new PDFSecurityConfigurationException("EncryptionHandlerState is not initialized");
}
return this.mCipher.update(buffer, start, len);
}
public byte[] finish() throws PDFSecurityException {
if (!this.mInited) {
throw new PDFSecurityConfigurationException("EncryptionHandlerState is not initialized");
}
try {
return this.mCipher.doFinal();
}
catch (IllegalStateException e) {
throw new PDFSecurityConfigurationException((Throwable)e);
}
catch (IllegalBlockSizeException e) {
throw new PDFSecurityConfigurationException((Throwable)e);
}
catch (BadPaddingException e) {
throw new PDFSecurityConfigurationException((Throwable)e);
}
}
}