forked from mirror/go-sqlcipher
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:
parent
122bc51f25
commit
d681773ef0
|
@ -1400,7 +1400,7 @@ func (d *SQLiteDriver) Open(dsn string) (driver.Conn, error) {
|
|||
// Encrypt Keys
|
||||
// The key pragma should be always called first
|
||||
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)
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -1207,7 +1207,7 @@ func TestEncryptoDatabase(t *testing.T) {
|
|||
defer os.Remove(tempFilename)
|
||||
defer db.Close()
|
||||
|
||||
_, err = db.Exec("PRAGMA key = 'password';")
|
||||
_, err = db.Exec(`PRAGMA key = "x'123ABC'";`)
|
||||
if err != nil {
|
||||
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")
|
||||
}
|
||||
db.Close()
|
||||
db, err = sql.Open("sqlite3", tempFilename+"?_key=not_password")
|
||||
db, err = sql.Open("sqlite3", tempFilename+"?_key=x'123000'")
|
||||
if err != nil {
|
||||
t.Fatal("Failed to open database:", err)
|
||||
}
|
||||
|
@ -1249,7 +1249,7 @@ func TestEncryptoDatabase(t *testing.T) {
|
|||
t.Error("Failed to encrypto database")
|
||||
}
|
||||
db.Close()
|
||||
db, err = sql.Open("sqlite3", tempFilename+"?_key=password")
|
||||
db, err = sql.Open("sqlite3", tempFilename+"?_key=x'123ABC'")
|
||||
if err != nil {
|
||||
t.Fatal("Failed to open database:", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue