go-sqlite3 icon indicating copy to clipboard operation
go-sqlite3 copied to clipboard

Connect to a Encrypted DB by C# System.Data.Sqlite

Open x0d3r opened this issue 11 years ago • 6 comments

Hello there, I have an application that's written on C# that has an sqlite db, encrypted by System.Data.Sqlite, the connection string is:

var con = "Data Source=c:\Windows\xxxdb;Initial Catalog=RobotsMaster;Version=3;Integrated Security=SSPI;Password=0xhgasfw;"

Now I'm working on re-write the app using go-sqlite3, using:

    db, err := sql.Open("sqlite3", "file:///C:/Windows/xxxdb?Password=0xhgasfw")
    if err != nil {
        log.Fatal(err.Error())
    }
    defer db.Close()

But I've got this error:

2014/12/12 09:25:32 file is encrypted or is not a database

It's possibly to use my encrypted db ?

Thanks !

x0d3r avatar Dec 12 '14 13:12 x0d3r

2 years later...

Maybe you can use the SQLite.Interop.dll and rename it to sqlite3.dll and move it to the system folder.

Then compile go-sqlite3 with the parameters to use the installed SQLite library: --tags libsqlite3

Remember that you must to use a PRAGMA key='0xhgasfw' right after opening the database.

kroggen avatar Jan 14 '17 06:01 kroggen

This library is a binding between SQLite3 and Golang, in order to open a encrypted Sqlite3 you have to use SQLCipher.

There are multiple golang bindings for it.

See: https://github.com/xeodou/go-sqlcipher

Can this be closed ?

gjrtimmer avatar May 22 '18 14:05 gjrtimmer

The PRAGMA key is part of SQLCipher/

gjrtimmer avatar May 22 '18 14:05 gjrtimmer

No, it is part of SQLite. It is just only enabled with additional code.

And System.Data.SQLite also has support for encryption as well as LiteReplica and LiteSync

kroggen avatar May 22 '18 15:05 kroggen

Would be great if this library has encryption @mattn is working on it on the see branch I think.

gjrtimmer avatar May 26 '18 19:05 gjrtimmer

I have added support for SQLCipher in the following PR: https://github.com/mattn/go-sqlite3/pull/1109

jgiannuzzi avatar Nov 22 '22 15:11 jgiannuzzi