public abstract class BaseCryptCodecHandler
extends java.lang.Object
implements com.healthmarketscience.jackcess.impl.CodecHandler
| Modifier and Type | Field and Description |
|---|---|
private com.healthmarketscience.jackcess.impl.PageChannel |
_channel |
private byte[] |
_encodingKey |
private KeyCache<org.bouncycastle.crypto.CipherParameters> |
_paramCache |
private com.healthmarketscience.jackcess.impl.TempBufferHolder |
_tempBufH |
static boolean |
CIPHER_DECRYPT_MODE |
static boolean |
CIPHER_ENCRYPT_MODE |
| Modifier | Constructor and Description |
|---|---|
protected |
BaseCryptCodecHandler(com.healthmarketscience.jackcess.impl.PageChannel channel,
byte[] encodingKey) |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
applyPageNumber(byte[] key,
int offset,
int pageNumber)
Returns a copy of the given key with the bytes of the given pageNumber
applied at the given offset using XOR.
|
protected void |
blockDecrypt(java.nio.ByteBuffer inPage,
java.nio.ByteBuffer outPage,
int pageNumber)
Decrypts the given buffer using a block cipher.
|
protected byte[] |
blockDecryptBytes(byte[] keyBytes,
byte[] iv,
byte[] encBytes)
Decrypts the given bytes using a block cipher configured with the given
key and IV into a new byte[].
|
protected java.nio.ByteBuffer |
blockEncrypt(java.nio.ByteBuffer buffer,
int pageNumber)
Encrypts the given buffer using a block cipher and returns the encrypted
buffer.
|
protected abstract org.bouncycastle.crypto.CipherParameters |
computeCipherParams(int pageNumber)
Generates the cipher parameters for the given page number.
|
protected static byte[] |
decryptBytes(org.bouncycastle.crypto.BufferedBlockCipher cipher,
byte[] encBytes)
Decrypts the given bytes using a block cipher into a new byte[].
|
protected static byte[] |
decryptBytes(StreamCipherCompat cipher,
byte[] encBytes)
Decrypts the given bytes using a stream cipher into a new byte[].
|
protected static org.bouncycastle.crypto.BufferedBlockCipher |
decryptInit(org.bouncycastle.crypto.BufferedBlockCipher cipher,
org.bouncycastle.crypto.CipherParameters params)
Inits the given cipher for decryption with the given params.
|
protected static StreamCipherCompat |
decryptInit(StreamCipherCompat cipher,
org.bouncycastle.crypto.CipherParameters params)
Inits the given cipher for decryption with the given params.
|
protected static org.bouncycastle.crypto.BufferedBlockCipher |
encryptInit(org.bouncycastle.crypto.BufferedBlockCipher cipher,
org.bouncycastle.crypto.CipherParameters params)
Inits the given cipher for encryption with the given params.
|
protected static StreamCipherCompat |
encryptInit(StreamCipherCompat cipher,
org.bouncycastle.crypto.CipherParameters params)
Inits the given cipher for encryption with the given params.
|
static byte[] |
fill(byte[] bytes,
int value)
Fills the given array with the given value and returns it.
|
static byte[] |
fixToLength(byte[] bytes,
int len) |
static byte[] |
fixToLength(byte[] bytes,
int len,
int padByte) |
protected org.bouncycastle.crypto.BufferedBlockCipher |
getBlockCipher() |
protected org.bouncycastle.crypto.CipherParameters |
getCipherParams(int pageNumber) |
protected byte[] |
getEncodingKey() |
protected byte[] |
getEncodingKey(int pageNumber)
Gets the encoding key combined with the given page number.
|
protected StreamCipherCompat |
getStreamCipher() |
protected java.nio.ByteBuffer |
getTempBuffer() |
static byte[] |
hash(org.bouncycastle.crypto.Digest digest,
byte[] bytes)
Hashes the given bytes using the given digest and returns the result.
|
static byte[] |
hash(org.bouncycastle.crypto.Digest digest,
byte[] bytes1,
byte[] bytes2)
Hashes the given bytes1 and bytes2 using the given digest and returns the
result.
|
static byte[] |
hash(org.bouncycastle.crypto.Digest digest,
byte[] bytes1,
byte[] bytes2,
int resultLen)
Hashes the given bytes1 and bytes2 using the given digest and returns the
hash fixed to the given length.
|
static byte[] |
hash(org.bouncycastle.crypto.Digest digest,
byte[] bytes,
int resultLen)
Hashes the given bytes using the given digest and returns the hash fixed
to the given length.
|
protected static boolean |
isBlankKey(byte[] key) |
protected static byte[] |
processBytesFully(org.bouncycastle.crypto.BufferedBlockCipher cipher,
byte[] inArray,
byte[] outArray,
int inLen)
Processes all the bytes for the given block cipher.
|
protected static java.nio.ByteBuffer |
readHeaderPage(com.healthmarketscience.jackcess.impl.PageChannel pageChannel)
Reads and returns the header page (page 0) from the given pageChannel.
|
protected void |
streamDecrypt(java.nio.ByteBuffer buffer,
int pageNumber)
Decrypts the given buffer using a stream cipher.
|
protected java.nio.ByteBuffer |
streamEncrypt(java.nio.ByteBuffer buffer,
int pageNumber,
int pageOffset)
Encrypts the given buffer using a stream cipher and returns the encrypted
buffer.
|
java.lang.String |
toString() |
static java.nio.ByteBuffer |
wrap(byte[] bytes) |
public static final boolean CIPHER_DECRYPT_MODE
public static final boolean CIPHER_ENCRYPT_MODE
private final com.healthmarketscience.jackcess.impl.PageChannel _channel
private final byte[] _encodingKey
private final KeyCache<org.bouncycastle.crypto.CipherParameters> _paramCache
private com.healthmarketscience.jackcess.impl.TempBufferHolder _tempBufH
protected BaseCryptCodecHandler(com.healthmarketscience.jackcess.impl.PageChannel channel,
byte[] encodingKey)
protected org.bouncycastle.crypto.CipherParameters getCipherParams(int pageNumber)
protected byte[] getEncodingKey()
protected StreamCipherCompat getStreamCipher()
protected org.bouncycastle.crypto.BufferedBlockCipher getBlockCipher()
protected java.nio.ByteBuffer getTempBuffer()
protected void streamDecrypt(java.nio.ByteBuffer buffer,
int pageNumber)
protected java.nio.ByteBuffer streamEncrypt(java.nio.ByteBuffer buffer,
int pageNumber,
int pageOffset)
protected void blockDecrypt(java.nio.ByteBuffer inPage,
java.nio.ByteBuffer outPage,
int pageNumber)
protected java.nio.ByteBuffer blockEncrypt(java.nio.ByteBuffer buffer,
int pageNumber)
public java.lang.String toString()
toString in class java.lang.Objectprotected static StreamCipherCompat decryptInit(StreamCipherCompat cipher, org.bouncycastle.crypto.CipherParameters params)
protected static StreamCipherCompat encryptInit(StreamCipherCompat cipher, org.bouncycastle.crypto.CipherParameters params)
protected static org.bouncycastle.crypto.BufferedBlockCipher decryptInit(org.bouncycastle.crypto.BufferedBlockCipher cipher,
org.bouncycastle.crypto.CipherParameters params)
protected static org.bouncycastle.crypto.BufferedBlockCipher encryptInit(org.bouncycastle.crypto.BufferedBlockCipher cipher,
org.bouncycastle.crypto.CipherParameters params)
protected static byte[] decryptBytes(StreamCipherCompat cipher, byte[] encBytes)
protected byte[] blockDecryptBytes(byte[] keyBytes,
byte[] iv,
byte[] encBytes)
protected static byte[] decryptBytes(org.bouncycastle.crypto.BufferedBlockCipher cipher,
byte[] encBytes)
protected byte[] getEncodingKey(int pageNumber)
protected static java.nio.ByteBuffer readHeaderPage(com.healthmarketscience.jackcess.impl.PageChannel pageChannel)
throws java.io.IOException
java.io.IOExceptionpublic static byte[] applyPageNumber(byte[] key,
int offset,
int pageNumber)
public static byte[] hash(org.bouncycastle.crypto.Digest digest,
byte[] bytes)
public static byte[] hash(org.bouncycastle.crypto.Digest digest,
byte[] bytes1,
byte[] bytes2)
public static byte[] hash(org.bouncycastle.crypto.Digest digest,
byte[] bytes,
int resultLen)
public static byte[] hash(org.bouncycastle.crypto.Digest digest,
byte[] bytes1,
byte[] bytes2,
int resultLen)
public static byte[] fixToLength(byte[] bytes,
int len)
public static byte[] fixToLength(byte[] bytes,
int len,
int padByte)
public static java.nio.ByteBuffer wrap(byte[] bytes)
public static byte[] fill(byte[] bytes,
int value)
protected static byte[] processBytesFully(org.bouncycastle.crypto.BufferedBlockCipher cipher,
byte[] inArray,
byte[] outArray,
int inLen)
throws org.bouncycastle.crypto.InvalidCipherTextException
org.bouncycastle.crypto.InvalidCipherTextExceptionprotected static boolean isBlankKey(byte[] key)
true if the given bytes are all 0, false
otherwiseprotected abstract org.bouncycastle.crypto.CipherParameters computeCipherParams(int pageNumber)