提交 d3c47d30 authored 作者: Thomas Mueller's avatar Thomas Mueller

FilePathCrypt > FilePathEncrypt

上级 64fcf884
...@@ -19,7 +19,7 @@ import org.h2.constant.ErrorCode; ...@@ -19,7 +19,7 @@ import org.h2.constant.ErrorCode;
import org.h2.constant.SysProperties; import org.h2.constant.SysProperties;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.security.SHA256; import org.h2.security.SHA256;
import org.h2.store.fs.FilePathCrypt; import org.h2.store.fs.FilePathEncrypt;
import org.h2.store.fs.FilePathRec; import org.h2.store.fs.FilePathRec;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.h2.util.New; import org.h2.util.New;
...@@ -314,7 +314,7 @@ public class ConnectionInfo implements Cloneable { ...@@ -314,7 +314,7 @@ public class ConnectionInfo implements Cloneable {
System.arraycopy(password, 0, filePassword, 0, space); System.arraycopy(password, 0, filePassword, 0, space);
Arrays.fill(password, (char) 0); Arrays.fill(password, (char) 0);
password = np; password = np;
fileEncryptionKey = FilePathCrypt.getPasswordBytes(filePassword); fileEncryptionKey = FilePathEncrypt.getPasswordBytes(filePassword);
filePasswordHash = hashPassword(passwordHash, "file", filePassword); filePasswordHash = hashPassword(passwordHash, "file", filePassword);
} }
userPasswordHash = hashPassword(passwordHash, user, password); userPasswordHash = hashPassword(passwordHash, user, password);
......
...@@ -25,15 +25,15 @@ import org.h2.util.MathUtils; ...@@ -25,15 +25,15 @@ import org.h2.util.MathUtils;
/** /**
* An encrypted file. * An encrypted file.
*/ */
public class FilePathCrypt extends FilePathWrapper { public class FilePathEncrypt extends FilePathWrapper {
private static final String SCHEME = "crypt"; private static final String SCHEME = "encrypt";
/** /**
* Register this file system. * Register this file system.
*/ */
public static void register() { public static void register() {
FilePath.register(new FilePathCrypt()); FilePath.register(new FilePathEncrypt());
} }
@Override @Override
...@@ -41,7 +41,7 @@ public class FilePathCrypt extends FilePathWrapper { ...@@ -41,7 +41,7 @@ public class FilePathCrypt extends FilePathWrapper {
String[] parsed = parse(name); String[] parsed = parse(name);
FileChannel file = FileUtils.open(parsed[1], mode); FileChannel file = FileUtils.open(parsed[1], mode);
byte[] passwordBytes = parsed[0].getBytes(Constants.UTF8); byte[] passwordBytes = parsed[0].getBytes(Constants.UTF8);
return new FileCrypt(name, passwordBytes, file); return new FileEncrypt(name, passwordBytes, file);
} }
@Override @Override
...@@ -62,10 +62,10 @@ public class FilePathCrypt extends FilePathWrapper { ...@@ -62,10 +62,10 @@ public class FilePathCrypt extends FilePathWrapper {
@Override @Override
public long size() { public long size() {
long size = getBase().size() - FileCrypt.HEADER_LENGTH; long size = getBase().size() - FileEncrypt.HEADER_LENGTH;
size = Math.max(0, size); size = Math.max(0, size);
if ((size & FileCrypt.BLOCK_SIZE_MASK) != 0) { if ((size & FileEncrypt.BLOCK_SIZE_MASK) != 0) {
size -= FileCrypt.BLOCK_SIZE; size -= FileEncrypt.BLOCK_SIZE;
} }
return size; return size;
} }
...@@ -123,7 +123,7 @@ public class FilePathCrypt extends FilePathWrapper { ...@@ -123,7 +123,7 @@ public class FilePathCrypt extends FilePathWrapper {
/** /**
* An encrypted file with a read cache. * An encrypted file with a read cache.
*/ */
public static class FileCrypt extends FileBase { public static class FileEncrypt extends FileBase {
/** /**
* The block size. * The block size.
...@@ -171,7 +171,7 @@ public class FilePathCrypt extends FilePathWrapper { ...@@ -171,7 +171,7 @@ public class FilePathCrypt extends FilePathWrapper {
private final String name; private final String name;
public FileCrypt(String name, byte[] encryptionKey, FileChannel base) throws IOException { public FileEncrypt(String name, byte[] encryptionKey, FileChannel base) throws IOException {
this.name = name; this.name = name;
this.base = base; this.base = base;
this.size = base.size() - HEADER_LENGTH; this.size = base.size() - HEADER_LENGTH;
......
...@@ -21,7 +21,7 @@ import org.h2.store.FileStore; ...@@ -21,7 +21,7 @@ import org.h2.store.FileStore;
import org.h2.store.fs.FileChannelInputStream; import org.h2.store.fs.FileChannelInputStream;
import org.h2.store.fs.FileChannelOutputStream; import org.h2.store.fs.FileChannelOutputStream;
import org.h2.store.fs.FilePath; import org.h2.store.fs.FilePath;
import org.h2.store.fs.FilePathCrypt; import org.h2.store.fs.FilePathEncrypt;
import org.h2.store.fs.FileUtils; import org.h2.store.fs.FileUtils;
import org.h2.util.Tool; import org.h2.util.Tool;
...@@ -152,11 +152,11 @@ public class ChangeFileEncryption extends Tool { ...@@ -152,11 +152,11 @@ public class ChangeFileEncryption extends Tool {
throw new SQLException("The file password may not contain spaces"); throw new SQLException("The file password may not contain spaces");
} }
} }
change.encryptKey = FilePathCrypt.getPasswordBytes(encryptPassword); change.encryptKey = FilePathEncrypt.getPasswordBytes(encryptPassword);
change.encrypt = getFileEncryptionKey(encryptPassword); change.encrypt = getFileEncryptionKey(encryptPassword);
} }
if (decryptPassword != null) { if (decryptPassword != null) {
change.decryptKey = FilePathCrypt.getPasswordBytes(decryptPassword); change.decryptKey = FilePathEncrypt.getPasswordBytes(decryptPassword);
change.decrypt = getFileEncryptionKey(decryptPassword); change.decrypt = getFileEncryptionKey(decryptPassword);
} }
change.out = out; change.out = out;
...@@ -213,14 +213,14 @@ public class ChangeFileEncryption extends Tool { ...@@ -213,14 +213,14 @@ public class ChangeFileEncryption extends Tool {
} }
FileChannel fileIn = FilePath.get(fileName).open("r"); FileChannel fileIn = FilePath.get(fileName).open("r");
if (decryptKey != null) { if (decryptKey != null) {
fileIn = new FilePathCrypt.FileCrypt(fileName, decryptKey, fileIn); fileIn = new FilePathEncrypt.FileEncrypt(fileName, decryptKey, fileIn);
} }
InputStream inStream = new FileChannelInputStream(fileIn, true); InputStream inStream = new FileChannelInputStream(fileIn, true);
String temp = directory + "/temp.db"; String temp = directory + "/temp.db";
FileUtils.delete(temp); FileUtils.delete(temp);
FileChannel fileOut = FilePath.get(temp).open("rw"); FileChannel fileOut = FilePath.get(temp).open("rw");
if (encryptKey != null) { if (encryptKey != null) {
fileOut = new FilePathCrypt.FileCrypt(temp, encryptKey, fileOut); fileOut = new FilePathEncrypt.FileEncrypt(temp, encryptKey, fileOut);
} }
OutputStream outStream = new FileChannelOutputStream(fileOut, true); OutputStream outStream = new FileChannelOutputStream(fileOut, true);
byte[] buffer = new byte[4 * 1024]; byte[] buffer = new byte[4 * 1024];
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论