Class BaseCryptCodecHandler
- java.lang.Object
-
- com.healthmarketscience.jackcess.crypt.impl.BaseCryptCodecHandler
-
- All Implemented Interfaces:
CodecHandler
- Direct Known Subclasses:
BaseJetCryptCodecHandler,OfficeCryptCodecHandler
public abstract class BaseCryptCodecHandler extends Object implements CodecHandler
Common CodecHandler support.- Author:
- Vladimir Berezniker
-
-
Field Summary
Fields Modifier and Type Field Description static booleanCIPHER_DECRYPT_MODEstatic booleanCIPHER_ENCRYPT_MODE
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidapplyHeaderMask(ByteBuffer page, JetFormat format)Removes the header mask from page 0, or puts it back.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.static intbits2bytes(int bits)static intcreateEncodingKey()Returns a page 0 key of the shape ms access writes.static BufferedBlockCipherdecryptInit(BufferedBlockCipher cipher, CipherParameters params)Inits the given cipher for decryption with the given params.static BufferedBlockCipherencryptInit(BufferedBlockCipher cipher, 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)static byte[]hash(Digest digest, byte[] bytes)Hashes the given bytes using the given digest and returns the result.static byte[]hash(Digest digest, byte[] bytes1, byte[] bytes2)Hashes the given bytes1 and bytes2 using the given digest and returns the result.static byte[]hash(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(Digest digest, byte[] bytes, int resultLen)Hashes the given bytes using the given digest and returns the hash fixed to the given length.static byte[]iterateHash(Digest digest, byte[] baseHash, int iterations)Hashes the given hash with its own iteration number, the given number of times.static byte[]processBytesFully(BufferedBlockCipher cipher, byte[] inArray)Runs the given block cipher over the given bytes into a new byte[].StringtoString()static ByteBufferwrap(byte[] bytes)-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.healthmarketscience.jackcess.impl.CodecHandler
canDecodeInline, canEncodePartialPage, decodePage, encodePage
-
-
-
-
Field Detail
-
CIPHER_DECRYPT_MODE
public static final boolean CIPHER_DECRYPT_MODE
- See Also:
- Constant Field Values
-
CIPHER_ENCRYPT_MODE
public static final boolean CIPHER_ENCRYPT_MODE
- See Also:
- Constant Field Values
-
-
Method Detail
-
decryptInit
public static BufferedBlockCipher decryptInit(BufferedBlockCipher cipher, CipherParameters params)
Inits the given cipher for decryption with the given params.
-
encryptInit
public static BufferedBlockCipher encryptInit(BufferedBlockCipher cipher, CipherParameters params)
Inits the given cipher for encryption with the given params.
-
processBytesFully
public static byte[] processBytesFully(BufferedBlockCipher cipher, byte[] inArray)
Runs the given block cipher over the given bytes into a new byte[]. The cipher carries the direction it was initialized for, so this both encrypts and decrypts.
-
applyPageNumber
public 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.
-
hash
public static byte[] hash(Digest digest, byte[] bytes)
Hashes the given bytes using the given digest and returns the result.
-
hash
public static byte[] hash(Digest digest, byte[] bytes1, byte[] bytes2)
Hashes the given bytes1 and bytes2 using the given digest and returns the result.
-
hash
public static byte[] hash(Digest digest, byte[] bytes, int resultLen)
Hashes the given bytes using the given digest and returns the hash fixed to the given length.
-
hash
public static byte[] hash(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.
-
iterateHash
public static byte[] iterateHash(Digest digest, byte[] baseHash, int iterations)
Hashes the given hash with its own iteration number, the given number of times. This is the work a spin count asks for.
-
fixToLength
public static byte[] fixToLength(byte[] bytes, int len)- Returns:
- a byte array of the given length, truncating or padding the given byte array as necessary.
-
fixToLength
public static byte[] fixToLength(byte[] bytes, int len, int padByte)- Returns:
- a byte array of the given length, truncating or padding the given byte array as necessary using the given padByte.
-
wrap
public static ByteBuffer wrap(byte[] bytes)
- Returns:
- a new ByteBuffer wrapping the given bytes with the appropriate byte order
-
applyHeaderMask
public static void applyHeaderMask(ByteBuffer page, JetFormat format)
Removes the header mask from page 0, or puts it back. The mask is xor, so the two are one operation.
-
createEncodingKey
public static int createEncodingKey()
Returns a page 0 key of the shape ms access writes. Ms access uses the windows tick count with0xa0a00000set, which makes the high bytes track how long the machine had been running. A random value with the same bits set is the same shape without being guessable, and nothing on the read path compares the key against anything but zero.
-
bits2bytes
public static int bits2bytes(int bits)
- Returns:
- the number of whole bytes the given number of bits holds
-
fill
public static byte[] fill(byte[] bytes, int value)Fills the given array with the given value and returns it.
-
-