mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
change the driver which is compatible with sqlcipher and modified the way to connect the encrypted sqlite db file
This commit is contained in:
1 parent
aa2761b10e
commit
f6da0c30ba
5 files changed
+61
-8
No files matched your search
@@ -1,5 +1,8 @@
|
||||
package minsecurity.identity.persist.sqlite;
|
||||
|
||||
import org.sqlite.mc.SQLiteMCConfig;
|
||||
import org.sqlite.mc.SQLiteMCSqlCipherConfig;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.*;
|
||||
|
||||
@@ -34,6 +37,10 @@ public class Sqlite {
|
||||
|
||||
}
|
||||
|
||||
private String passwd2HexKey(){
|
||||
return String.format("x'%s'", passwd);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Sqlite object
|
||||
* @return Sqlite object
|
||||
@@ -70,8 +77,8 @@ public class Sqlite {
|
||||
new File(dbPath).mkdirs();
|
||||
}
|
||||
String real_db_file = dbPath + db_file;
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
c = DriverManager.getConnection("jdbc:sqlite:" + real_db_file);
|
||||
// 兼容sqlcipher
|
||||
c = DriverManager.getConnection("jdbc:sqlite:" + real_db_file, SQLiteMCSqlCipherConfig.getV4Defaults().withKey(passwd2HexKey()).toProperties());
|
||||
stmt = c.createStatement();
|
||||
stmt.executeUpdate(table_create);
|
||||
stmt.close();
|
||||
@@ -92,8 +99,8 @@ public class Sqlite {
|
||||
new File(filePath).mkdirs();
|
||||
}
|
||||
String real_db_file = filePath + db_file;
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
c = DriverManager.getConnection("jdbc:sqlite:" + real_db_file);
|
||||
// 兼容sqlcipher
|
||||
c = DriverManager.getConnection("jdbc:sqlite:" + real_db_file, SQLiteMCSqlCipherConfig.getV4Defaults().withKey(passwd2HexKey()).toProperties());
|
||||
stmt = c.createStatement();
|
||||
stmt.executeUpdate(table_create);
|
||||
stmt.close();
|
||||
@@ -111,7 +118,8 @@ public class Sqlite {
|
||||
try{
|
||||
String real_db_file = db_path + db_file;
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
c = DriverManager.getConnection("jdbc:sqlite:" + real_db_file);
|
||||
// 兼容sqlcipher
|
||||
c = DriverManager.getConnection("jdbc:sqlite:" + real_db_file, SQLiteMCSqlCipherConfig.getV4Defaults().withKey(passwd2HexKey()).toProperties());
|
||||
// TODO 设置数据库最大连接数
|
||||
return c;
|
||||
}catch (Exception ex){
|
||||
|
||||
Reference in new issue
Block a user