Skip to content

Commit 1e4f173

Browse files
committed
included maven; updated readme
1 parent 9978e2a commit 1e4f173

File tree

17 files changed

+279
-100
lines changed

17 files changed

+279
-100
lines changed

README.md

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,67 @@
11
SQLite-Encryption
22
============================
33

4-
The SQLite-Encryption is a Java based utility which allows you to convert an SQLite Database into an encrypted .sqlite file. Four different encryption algorithms are supported:
4+
The SQLite-Encryption is a Java based utility which allows you to convert an SQLite Database into an encrypted .sqlite file. Three different encryption algorithms are supported:
55

6+
```
67
shift cipher
78
substitution cipher
89
transposition cipher
9-
10+
```
11+
1012
These encryption algorithms are less secure compared to [AES](https://www.sqlite.org/see/doc/trunk/www/readme.wiki), but are more efficient in terms of storage and complexity.
1113
The AES based encryption has performance issues during bulk DML-based operation.
12-
It also increased the size of the database by 70%. On the contrary, these basic ciphers provides efficiency at the cost of reduced security.
14+
It also increases the size of the database by 70%. On the contrary, these basic ciphers provides efficiency at the cost of reduced security.
1315

1416
## How to Compile it
1517

16-
Build script currently generates only solution
1718

1819
#### 1. Requirements
1920

20-
- [sqlite-jdbc-3.32.3.2.jar](https://github.com/xerial/sqlite-jdbc)
21+
- [sqlite-jdbc-3.32.3.2](https://github.com/xerial/sqlite-jdbc)
22+
- [org.json](https://mvnrepository.com/artifact/org.json/json/20200518)
23+
24+
It is already included the POM.xml of the project. Run Maven build to download it.
2125

2226
#### 2. Steps
2327

24-
1. [Download snapshot of this repository][SQLite-Encryption], unzip and open it
25-
2. Run
28+
1. [Download snapshot of this repository][SQLite-Encryption], unzip and open it. **use IntelliJ IDEA to open the project**
29+
30+
2. Configuration
31+
32+
You can configure the following parameter in the App.java file
33+
34+
```
35+
String DATABASE_NAME = "test.db" //path to the sqlite db
36+
String CONFIG_FILE_NAME = "table_col_map.json" //path to the json file which has table column mapping
37+
````
38+
39+
The **table_col_map.json** contains the tables, their primary key and the columns to be encrypted.
40+
You need to update it as per your db schema.
41+
42+
```json
43+
[{
44+
"tableName": "Customer",
45+
"primaryKey": "CustomerId",
46+
"toEncrypt": [
47+
"FirstName",
48+
"LastName",
49+
"Company"
50+
]},
51+
...
52+
]
53+
```
54+
55+
56+
**run using IntelliJ IDEA**
2657

27-
**Following these steps and building all binaries in their out directory**
58+
OR
2859

60+
3. Run in terminal
61+
```
62+
javac src/co.techelix/*.java -d classes
63+
java -cp classes App.java
64+
````
2965
3066
## Issues
3167
@@ -51,10 +87,10 @@ For making contribution:
5187
5288
```
5389
git clone https://github.com/wahabjawed/SQLite-Encryption.git
54-
cd dbEncrypt
90+
cd SQLiteEncrypt
5591
```
5692
57-
use IntelliJ IDEA to open the project
93+
**use IntelliJ IDEA to open the project**
5894
5995
### Contributers
6096

SQLiteEncrypt.iml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4" />

dbEncrypt/dbEncrypt.iml

Lines changed: 0 additions & 29 deletions
This file was deleted.
-6.88 MB
Binary file not shown.

dbEncrypt/src/co/techelix/Main.java

Lines changed: 0 additions & 59 deletions
This file was deleted.

dbEncrypt/table_col_map.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

pom.xml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.example</groupId>
8+
<artifactId>SQLiteEncrypt</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<name>SQLiteEncrypt</name>
12+
<!-- FIXME change it to the project's website -->
13+
<url>http://www.example.com</url>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
<maven.compiler.source>1.7</maven.compiler.source>
18+
<maven.compiler.target>1.7</maven.compiler.target>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>junit</groupId>
24+
<artifactId>junit</artifactId>
25+
<version>4.11</version>
26+
<scope>test</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.xerial</groupId>
30+
<artifactId>sqlite-jdbc</artifactId>
31+
<version>3.32.3.2</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.json</groupId>
35+
<artifactId>json</artifactId>
36+
<version>20200518</version>
37+
</dependency>
38+
</dependencies>
39+
40+
<build>
41+
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
42+
<plugins>
43+
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
44+
<plugin>
45+
<artifactId>maven-clean-plugin</artifactId>
46+
<version>3.1.0</version>
47+
</plugin>
48+
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
49+
<plugin>
50+
<artifactId>maven-resources-plugin</artifactId>
51+
<version>3.0.2</version>
52+
</plugin>
53+
<plugin>
54+
<artifactId>maven-compiler-plugin</artifactId>
55+
<version>3.8.0</version>
56+
</plugin>
57+
<plugin>
58+
<artifactId>maven-surefire-plugin</artifactId>
59+
<version>2.22.1</version>
60+
</plugin>
61+
<plugin>
62+
<artifactId>maven-jar-plugin</artifactId>
63+
<version>3.0.2</version>
64+
</plugin>
65+
<plugin>
66+
<artifactId>maven-install-plugin</artifactId>
67+
<version>2.5.2</version>
68+
</plugin>
69+
<plugin>
70+
<artifactId>maven-deploy-plugin</artifactId>
71+
<version>2.8.2</version>
72+
</plugin>
73+
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
74+
<plugin>
75+
<artifactId>maven-site-plugin</artifactId>
76+
<version>3.7.1</version>
77+
</plugin>
78+
<plugin>
79+
<artifactId>maven-project-info-reports-plugin</artifactId>
80+
<version>3.0.0</version>
81+
</plugin>
82+
</plugins>
83+
</pluginManagement>
84+
</build>
85+
</project>

src/main/java/co/techelix/App.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package co.techelix;
2+
3+
import co.techelix.cipher.ICipher;
4+
import co.techelix.cipher.ShiftCipher;
5+
import org.json.JSONArray;
6+
import org.json.JSONObject;
7+
8+
import java.io.BufferedReader;
9+
import java.io.FileReader;
10+
import java.util.*;
11+
12+
/**
13+
* The type Main.
14+
*/
15+
public class App {
16+
17+
/**
18+
* The constant DATABASE_NAME.
19+
*/
20+
public static final String DATABASE_NAME = "test.sqlite";
21+
/**
22+
* The constant CONFIGURATION_FILE_NAME.
23+
*/
24+
public static final String CONFIG_FILE_NAME = "table_col_map.json";
25+
26+
/**
27+
* The entry point of application.
28+
*
29+
* @param args the input arguments
30+
*/
31+
public static void main(String[] args) {
32+
33+
Map<String, List<String>> tableColumnMapList = generateTableColMapFromJSON(CONFIG_FILE_NAME);
34+
35+
ICipher cipher = new ShiftCipher(4);
36+
37+
DBEncryptor encryptor = new DBEncryptor()
38+
.setCipher(cipher)
39+
.setDatabaseName(DATABASE_NAME)
40+
.setTableColumnMapList(tableColumnMapList);
41+
42+
encryptor.execute();
43+
}
44+
45+
46+
private static Map<String, List<String>> generateTableColMapFromJSON(String fileName) {
47+
Map<String, List<String>> tableColumnMapList = new HashMap<>();
48+
String fileContent = Util.openAndReadFile(fileName);
49+
50+
if(fileContent !=null){
51+
52+
JSONArray jsonArr = new JSONArray(fileContent);
53+
54+
JSONObject tableObj;
55+
List colList;
56+
for (int i = 0; i < jsonArr.length(); i++) {
57+
tableObj = jsonArr.getJSONObject(i);
58+
colList = new ArrayList();
59+
60+
colList.add(tableObj.getString("primaryKey"));
61+
colList.addAll(tableObj.getJSONArray("toEncrypt").toList());
62+
63+
tableColumnMapList.put(tableObj.getString("tableName"), colList);
64+
}
65+
66+
}
67+
68+
return tableColumnMapList;
69+
}
70+
71+
72+
73+
74+
}

dbEncrypt/src/co/techelix/DBEncryptor.java renamed to src/main/java/co/techelix/DBEncryptor.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package co.techelix;
22

3+
34
import co.techelix.cipher.ICipher;
45

56
import java.sql.*;
@@ -165,6 +166,7 @@ public void execute() {
165166

166167
for (Map.Entry<String, List<String>> tableColumnMap : tableColumnMapList.entrySet()) {
167168

169+
System.out.println("Working With Table: "+tableColumnMap.getKey());
168170
String fetchSQLStatement = generateSelectStatement(tableColumnMap);
169171
String updateSQLStatement = generateUpdateStatement(tableColumnMap);
170172

@@ -214,7 +216,14 @@ private boolean batchUpdate(String sql, ResultSet rs, Map.Entry<String, List<Str
214216
int paramIndex = 1;
215217

216218
for (int i = 1; i < tableColumnMap.getValue().size(); i++) {
217-
preparedStatement.setString(paramIndex, cipher.encode(rs.getString(tableColumnMap.getValue().get(i))));
219+
220+
String toUpdateValue =rs.getString(tableColumnMap.getValue().get(i));
221+
222+
if(toUpdateValue == null){
223+
preparedStatement.setString(paramIndex,null);
224+
}else{
225+
preparedStatement.setString(paramIndex, cipher.encode(rs.getString(tableColumnMap.getValue().get(i))));
226+
}
218227
paramIndex++;
219228
}
220229
preparedStatement.setInt(paramIndex, rs.getInt(tableColumnMap.getValue().get(0)));

0 commit comments

Comments
 (0)