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

FilePathCrypt > FilePathEncrypt

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