xeodou / go-sqlcipher

Golang SQLCipher driver conforming to the built-in database/sql interface and using the latest sqlite3 code.
MIT License
224 stars 52 forks source link

"panic: file is not a database" #32

Open MasterGroosha opened 2 years ago

MasterGroosha commented 2 years ago

Hello and excuse me for a strange question.

I've started maintaining our company's small project written in Go. It uses SQLite3 and your go-sqlcipher, also Gorm v1 and labstack/echo as a simple web server.

I have an old binary build which works this way:

  1. During the first run, the database is ciphered with a random key. 3 subkeys are computed and printed (2 of them are enough to reproduce the key). PRAGMA key ... is issued and application runs fine.
  2. During the other runs, the application opens the database, but since it is encrypted, it justs waits for keys to be put via HTTP request to unseal the DB file.

However, on the second run, I get "panic: file is not a database" error. The easiest way to reproduce this is to use your encrypto example: https://github.com/xeodou/go-sqlcipher/blob/master/_example/encrypto/encrypto.go Run it once, everything is fine. Run it twice without ?key=123456, you get the error. To skip the error, you need to pass ?key=123456 with db path. However, the app I'm maintaining used to work without this addition.

So my question is: which version of go-sqlcipher should I use to keep the old behavior?