#20 Make PRAGMA key to quotes (#21)

In SQLCipher it's allowed to use different keys (not only alphanumeric).
https://www.zetetic.net/sqlcipher/sqlcipher-api/#PRAGMA_key

Co-authored-by: Vladimir.Kasatkin <Vladimir.Kasatkin@acronis.com>
This commit is contained in:
Vladimir Kasatkin 2020-07-27 11:03:46 +03:00 committed by GitHub
parent 122bc51f25
commit d681773ef0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -1400,7 +1400,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
// Encrypt Keys // Encrypt Keys
// The key pragma should be always called first // The key pragma should be always called first
if encryptKey != "" { if encryptKey != "" {
if err := exec(fmt.Sprintf("PRAGMA key = %s;", encryptKey)); err != nil { if err := exec(fmt.Sprintf(`PRAGMA key = "%s";`, encryptKey)); err != nil {
C.sqlite3_close_v2(db) C.sqlite3_close_v2(db)
return nil, err return nil, err
} }

View File

@ -1207,7 +1207,7 @@ func TestEncryptoDatabase(t *testing.T) {
defer os.Remove(tempFilename) defer os.Remove(tempFilename)
defer db.Close() defer db.Close()
_, err = db.Exec("PRAGMA key = 'password';") _, err = db.Exec(`PRAGMA key = "x'123ABC'";`)
if err != nil { if err != nil {
t.Error("Failed to set encrypto key") t.Error("Failed to set encrypto key")
} }
@ -1239,7 +1239,7 @@ func TestEncryptoDatabase(t *testing.T) {
t.Error("Failed to db.QueryRow: not matched results") t.Error("Failed to db.QueryRow: not matched results")
} }
db.Close() db.Close()
db, err = sql.Open("sqlite3", tempFilename+"?_key=not_password") db, err = sql.Open("sqlite3", tempFilename+"?_key=x'123000'")
if err != nil { if err != nil {
t.Fatal("Failed to open database:", err) t.Fatal("Failed to open database:", err)
} }
@ -1249,7 +1249,7 @@ func TestEncryptoDatabase(t *testing.T) {
t.Error("Failed to encrypto database") t.Error("Failed to encrypto database")
} }
db.Close() db.Close()
db, err = sql.Open("sqlite3", tempFilename+"?_key=password") db, err = sql.Open("sqlite3", tempFilename+"?_key=x'123ABC'")
if err != nil { if err != nil {
t.Fatal("Failed to open database:", err) t.Fatal("Failed to open database:", err)
} }