Sqlite3_open succeeded, followed by the following code:
Copy content to clipboard
Code:
int i;
// Add and use a password
i = sqlite3_key( db, "dcg", 3 );
// Change the password
i = sqlite3_rekey( db, "dcg", 0 );
Use the sqlite3_key function to submit the password., K % Y, ^ 9 x * W & F1 L/} % v
: G, Q! The C (Z + H (K5} # J & I 1st parameter is a sqlite3 * type variable, representing the database opened with sqlite3_open (or the new database ).
8 K + P & @ & R1 _ (J # V + P
3 C9 [* r'n'/N, F. The 2nd parameters are keys. 5 V0 Y. O & V & T3 Y3 F; O; E8 R
-A9 v. H5 @/W 3rd parameters are the key length. $ T0 H1 S (V' v % y7 N ,~ /H #~ (E
(J/[-N4 y'u2 G! ] 8 U % J4 D /{Use sqlite3_rekey to change the password. The parameter description is the same as sqlite3_key.
; {/O; I. S ;~ # P0 A4 J
(] 0 A & W/R % N6 w 0? /I * d (y-T9 B/Z + \. n
# A D1 J2 S4 U4 P
In fact, you can call sqlite3_key to set the password at any location before the sqlite3_open function and before the sqlite3_close function.
4'6 |; V: P9 S's
3 h c % J: s! ? 0 s (k h-] But if you do not set a password, and the database has a password before, then you will get a return value for any operation: sqlite_notadb, and get the error prompt: "file is encrypted or is not a database ".
# I ~ # C % M9 @ 2 W (O "A, M '~ 2 U $ H/F %]
The database works normally only when you set the correct password with sqlite3_key.
) L' {"P' A * H/D % ^ * F! F $ G
* {"M) {&]; y' o if you want to change the password, you must first enable sqlite3_open to open the database, and then sqlite3_key to set the key, then you can use sqlite3_rekey to change the password.
# H, U4 c) J-T % t
: D (L3 I. [. Y if the database has a password, but you do not use sqlite3_key to set a password, then sqlite_notadb will be returned when you try to use sqlite3_rekey to change the password.
. N: V' ^, J %} 4 m) L) M4 I
6 L 'e1 i7 K * P. [9 N. J. If you need to clear the password, you can use:
Copy content to clipboard
Code:
// Change the password
i = sqlite3_rekey( db, NULL, 0 );
To clear the password.