Package org.h2.security
Class SecureFileStore
- java.lang.Object
-
- org.h2.store.FileStore
-
- org.h2.security.SecureFileStore
-
public class SecureFileStore extends FileStore
A file store that encrypts all data before writing, and decrypts all data after reading. Areas that were never written to (for example after calling setLength to enlarge the file) are not encrypted (contains 0 bytes).
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
buffer
private byte[]
bufferForInitVector
private BlockCipher
cipher
private BlockCipher
cipherForInitVector
private byte[]
key
private int
keyIterations
private long
pos
-
Fields inherited from class org.h2.store.FileStore
HEADER_LENGTH, name
-
-
Constructor Summary
Constructors Constructor Description SecureFileStore(DataHandler handler, java.lang.String name, java.lang.String mode, java.lang.String cipher, byte[] key, int keyIterations)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected byte[]
generateSalt()
Generate the random salt bytes if required.protected void
initKey(byte[] salt)
Initialize the key using the given salt.void
readFully(byte[] b, int off, int len)
Read a number of bytes.void
readFullyDirect(byte[] b, int off, int len)
Read a number of bytes without decrypting.void
seek(long x)
Go to the specified file location.void
write(byte[] b, int off, int len)
Write a number of bytes.protected void
writeDirect(byte[] b, int off, int len)
Write a number of bytes without encrypting.private void
xorInitVector(byte[] b, int off, int len, long p)
-
Methods inherited from class org.h2.store.FileStore
autoDelete, close, closeAndDeleteSilently, closeFile, closeSilently, getFilePointer, init, length, open, open, open, openFile, releaseLock, setCheckedWriting, setLength, stopAutoDelete, sync, tryLock
-
-
-
-
Field Detail
-
key
private byte[] key
-
cipher
private final BlockCipher cipher
-
cipherForInitVector
private final BlockCipher cipherForInitVector
-
buffer
private byte[] buffer
-
pos
private long pos
-
bufferForInitVector
private final byte[] bufferForInitVector
-
keyIterations
private final int keyIterations
-
-
Constructor Detail
-
SecureFileStore
public SecureFileStore(DataHandler handler, java.lang.String name, java.lang.String mode, java.lang.String cipher, byte[] key, int keyIterations)
-
-
Method Detail
-
generateSalt
protected byte[] generateSalt()
Description copied from class:FileStore
Generate the random salt bytes if required.- Overrides:
generateSalt
in classFileStore
- Returns:
- the random salt or the magic
-
initKey
protected void initKey(byte[] salt)
Description copied from class:FileStore
Initialize the key using the given salt.
-
writeDirect
protected void writeDirect(byte[] b, int off, int len)
Description copied from class:FileStore
Write a number of bytes without encrypting.- Overrides:
writeDirect
in classFileStore
- Parameters:
b
- the source bufferoff
- the offsetlen
- the number of bytes to write
-
write
public void write(byte[] b, int off, int len)
Description copied from class:FileStore
Write a number of bytes.
-
readFullyDirect
public void readFullyDirect(byte[] b, int off, int len)
Description copied from class:FileStore
Read a number of bytes without decrypting.- Overrides:
readFullyDirect
in classFileStore
- Parameters:
b
- the target bufferoff
- the offsetlen
- the number of bytes to read
-
readFully
public void readFully(byte[] b, int off, int len)
Description copied from class:FileStore
Read a number of bytes.
-
seek
public void seek(long x)
Description copied from class:FileStore
Go to the specified file location.
-
xorInitVector
private void xorInitVector(byte[] b, int off, int len, long p)
-
-