@capgo/capacitor-data-storage-sqlite 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorDataStorageSqlite.podspec +18 -0
- package/LICENSE +21 -0
- package/android/build.gradle +63 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/CapacitorDataStorageSqlite.java +387 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/CapacitorDataStorageSqlitePlugin.java +447 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/RetHandler.java +117 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/Data.java +8 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/Global.java +7 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonStore.java +131 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonTable.java +110 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonValue.java +89 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/StorageDatabaseHelper.java +691 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/UtilsSQLCipher.java +162 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +995 -0
- package/dist/esm/definitions.d.ts +296 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web-utils/Data.d.ts +5 -0
- package/dist/esm/web-utils/Data.js +3 -0
- package/dist/esm/web-utils/Data.js.map +1 -0
- package/dist/esm/web-utils/StorageDatabaseHelper.d.ts +23 -0
- package/dist/esm/web-utils/StorageDatabaseHelper.js +247 -0
- package/dist/esm/web-utils/StorageDatabaseHelper.js.map +1 -0
- package/dist/esm/web-utils/json-utils.d.ts +15 -0
- package/dist/esm/web-utils/json-utils.js +76 -0
- package/dist/esm/web-utils/json-utils.js.map +1 -0
- package/dist/esm/web.d.ts +27 -0
- package/dist/esm/web.js +295 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +633 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +635 -0
- package/dist/plugin.js.map +1 -0
- package/electron/dist/plugin.js +1044 -0
- package/electron/dist/plugin.js.map +1 -0
- package/electron/rollup.config.mjs +17 -0
- package/electron/tsconfig.json +19 -0
- package/ios/Plugin/CapacitorDataStorageSqlite.swift +550 -0
- package/ios/Plugin/CapacitorDataStorageSqlitePlugin.h +10 -0
- package/ios/Plugin/CapacitorDataStorageSqlitePlugin.m +29 -0
- package/ios/Plugin/CapacitorDataStorageSqlitePlugin.swift +550 -0
- package/ios/Plugin/Data.swift +16 -0
- package/ios/Plugin/Global.swift +13 -0
- package/ios/Plugin/ImportExportJson/JsonStore.swift +47 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/ReturnHandler.swift +85 -0
- package/ios/Plugin/StorageDatabaseHelper.swift +603 -0
- package/ios/Plugin/Utils/Blob.swift +41 -0
- package/ios/Plugin/Utils/UtilsBinding.swift +73 -0
- package/ios/Plugin/Utils/UtilsEncryption.swift +79 -0
- package/ios/Plugin/Utils/UtilsFile.swift +244 -0
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +605 -0
- package/package.json +96 -0
- package/readme.md +203 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
package com.jeep.plugin.capacitor.capacitordatastoragesqlite.cdssUtils;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import java.io.File;
|
|
5
|
+
import java.io.FileNotFoundException;
|
|
6
|
+
import java.io.IOException;
|
|
7
|
+
import net.sqlcipher.database.SQLiteDatabase;
|
|
8
|
+
import net.sqlcipher.database.SQLiteException;
|
|
9
|
+
import net.sqlcipher.database.SQLiteStatement;
|
|
10
|
+
|
|
11
|
+
public class UtilsSQLCipher {
|
|
12
|
+
|
|
13
|
+
private static final String TAG = UtilsSQLCipher.class.getName();
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The detected state of the database, based on whether we can
|
|
17
|
+
* open it without a passphrase, with the passphrase 'secret'.
|
|
18
|
+
*/
|
|
19
|
+
public enum State {
|
|
20
|
+
DOES_NOT_EXIST,
|
|
21
|
+
UNENCRYPTED,
|
|
22
|
+
ENCRYPTED_SECRET,
|
|
23
|
+
ENCRYPTED_NEW_SECRET,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Determine whether or not this database appears to be encrypted,
|
|
28
|
+
* based on whether we can open it without a passphrase or with
|
|
29
|
+
* the passphrase 'secret'.
|
|
30
|
+
*
|
|
31
|
+
* @param dbPath a File pointing to the database
|
|
32
|
+
* @param globVar an instance of Global
|
|
33
|
+
* @return the detected state of the database
|
|
34
|
+
*/
|
|
35
|
+
public State getDatabaseState(File dbPath, Global globVar) {
|
|
36
|
+
if (dbPath.exists()) {
|
|
37
|
+
SQLiteDatabase db = null;
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
db = SQLiteDatabase.openDatabase(
|
|
41
|
+
dbPath.getAbsolutePath(),
|
|
42
|
+
"",
|
|
43
|
+
null,
|
|
44
|
+
SQLiteDatabase.OPEN_READONLY
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
db.getVersion();
|
|
48
|
+
|
|
49
|
+
return (State.UNENCRYPTED);
|
|
50
|
+
} catch (Exception e) {
|
|
51
|
+
try {
|
|
52
|
+
db = SQLiteDatabase.openDatabase(
|
|
53
|
+
dbPath.getAbsolutePath(),
|
|
54
|
+
globVar.secret,
|
|
55
|
+
null,
|
|
56
|
+
SQLiteDatabase.OPEN_READONLY
|
|
57
|
+
);
|
|
58
|
+
return (State.ENCRYPTED_SECRET);
|
|
59
|
+
} catch (Exception e1) {
|
|
60
|
+
return (State.ENCRYPTED_NEW_SECRET);
|
|
61
|
+
}
|
|
62
|
+
} finally {
|
|
63
|
+
if (db != null) {
|
|
64
|
+
db.close();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (State.DOES_NOT_EXIST);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Replaces this database with a version encrypted with the supplied
|
|
74
|
+
* passphrase, deleting the original.
|
|
75
|
+
* Do not call this while the database is open.
|
|
76
|
+
*
|
|
77
|
+
* The passphrase is untouched in this call.
|
|
78
|
+
*
|
|
79
|
+
* @param ctxt a Context
|
|
80
|
+
* @param originalFile a File pointing to the database
|
|
81
|
+
* @param passphrase the passphrase from the user
|
|
82
|
+
* @throws IOException
|
|
83
|
+
*/
|
|
84
|
+
public void encrypt(Context ctxt, File originalFile, byte[] passphrase)
|
|
85
|
+
throws IOException {
|
|
86
|
+
SQLiteDatabase.loadLibs(ctxt);
|
|
87
|
+
|
|
88
|
+
if (originalFile.exists()) {
|
|
89
|
+
File newFile = File.createTempFile(
|
|
90
|
+
"sqlcipherutils",
|
|
91
|
+
"tmp",
|
|
92
|
+
ctxt.getCacheDir()
|
|
93
|
+
);
|
|
94
|
+
SQLiteDatabase db = SQLiteDatabase.openDatabase(
|
|
95
|
+
originalFile.getAbsolutePath(),
|
|
96
|
+
"",
|
|
97
|
+
null,
|
|
98
|
+
SQLiteDatabase.OPEN_READWRITE
|
|
99
|
+
);
|
|
100
|
+
int version = db.getVersion();
|
|
101
|
+
|
|
102
|
+
db.close();
|
|
103
|
+
|
|
104
|
+
db = SQLiteDatabase.openDatabase(
|
|
105
|
+
newFile.getAbsolutePath(),
|
|
106
|
+
passphrase,
|
|
107
|
+
null,
|
|
108
|
+
SQLiteDatabase.OPEN_READWRITE,
|
|
109
|
+
null,
|
|
110
|
+
null
|
|
111
|
+
);
|
|
112
|
+
StringBuilder sql = new StringBuilder();
|
|
113
|
+
sql.append("ATTACH DATABASE ? AS plaintext KEY ");
|
|
114
|
+
sql.append("'';");
|
|
115
|
+
final SQLiteStatement st = db.compileStatement(sql.toString());
|
|
116
|
+
|
|
117
|
+
st.bindString(1, originalFile.getAbsolutePath());
|
|
118
|
+
st.execute();
|
|
119
|
+
|
|
120
|
+
db.rawExecSQL("SELECT sqlcipher_export('main', 'plaintext')");
|
|
121
|
+
db.rawExecSQL("DETACH DATABASE plaintext");
|
|
122
|
+
db.setVersion(version);
|
|
123
|
+
st.close();
|
|
124
|
+
db.close();
|
|
125
|
+
|
|
126
|
+
originalFile.delete();
|
|
127
|
+
newFile.renameTo(originalFile);
|
|
128
|
+
} else {
|
|
129
|
+
throw new FileNotFoundException(
|
|
130
|
+
originalFile.getAbsolutePath() + " not found"
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public void changePassword(
|
|
136
|
+
Context ctxt,
|
|
137
|
+
File file,
|
|
138
|
+
String password,
|
|
139
|
+
String nwpassword
|
|
140
|
+
) throws IOException {
|
|
141
|
+
SQLiteDatabase.loadLibs(ctxt);
|
|
142
|
+
|
|
143
|
+
if (file.exists()) {
|
|
144
|
+
SQLiteDatabase db = SQLiteDatabase.openDatabase(
|
|
145
|
+
file.getAbsolutePath(),
|
|
146
|
+
password,
|
|
147
|
+
null,
|
|
148
|
+
SQLiteDatabase.OPEN_READWRITE
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
if (!db.isOpen()) {
|
|
152
|
+
throw new SQLiteException(
|
|
153
|
+
"database " + file.getAbsolutePath() + " open failed"
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
db.changePassword(nwpassword);
|
|
157
|
+
db.close();
|
|
158
|
+
} else {
|
|
159
|
+
throw new FileNotFoundException(file.getAbsolutePath() + " not found");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
File without changes
|