@@ -781,6 +781,8 @@ func errorString(err Error) string {
781
781
// Enable or disable enforcement of foreign keys. X can be 1 or 0.
782
782
// _recursive_triggers=X
783
783
// Enable or disable recursive triggers. X can be 1 or 0.
784
+ // _crypto_key=XXX
785
+ // Specify symmetric crypto key for use by SEE. X must be text key without quotes.
784
786
func (d * SQLiteDriver ) Open (dsn string ) (driver.Conn , error ) {
785
787
if C .sqlite3_threadsafe () == 0 {
786
788
return nil , errors .New ("sqlite library was not compiled for thread-safe operation" )
@@ -791,6 +793,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
791
793
busyTimeout := 5000
792
794
foreignKeys := - 1
793
795
recursiveTriggers := - 1
796
+ cryptoKey := ""
794
797
pos := strings .IndexRune (dsn , '?' )
795
798
if pos >= 1 {
796
799
params , err := url .ParseQuery (dsn [pos + 1 :])
@@ -857,6 +860,9 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
857
860
}
858
861
}
859
862
863
+ // _crypto_key
864
+ cryptoKey = params .Get ("_crypto_key" )
865
+
860
866
if ! strings .HasPrefix (dsn , "file:" ) {
861
867
dsn = dsn [:pos ]
862
868
}
@@ -915,6 +921,16 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
915
921
}
916
922
}
917
923
924
+ // crypto key must be specified BEFORE any other action
925
+ // and works only with SEE version of Sqlite3
926
+ if cryptoKey != "" {
927
+ tmp := fmt .Sprintf ("PRAGMA key = '%s'" , strings .Replace (cryptoKey , "'" , "''" , - 1 ))
928
+ if err := exec (tmp ); err != nil {
929
+ C .sqlite3_close_v2 (db )
930
+ return nil , err
931
+ }
932
+ }
933
+
918
934
conn := & SQLiteConn {db : db , loc : loc , txlock : txlock }
919
935
920
936
if len (d .Extensions ) > 0 {
0 commit comments