2020-08-20 03:03:20 +00:00
|
|
|
## go-sqlcipher
|
|
|
|
|
|
|
|
[![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/mutecomm/go-sqlcipher) [![CI](https://github.com/mutecomm/go-sqlcipher/workflows/CI/badge.svg)](https://github.com/mutecomm/go-sqlcipher/actions)
|
2015-04-28 23:56:53 +00:00
|
|
|
|
2015-09-27 06:01:47 +00:00
|
|
|
### Description
|
2015-04-28 23:56:53 +00:00
|
|
|
|
|
|
|
Self-contained Go sqlite3 driver with an AES-256 encrypted sqlite3 database
|
|
|
|
conforming to the built-in database/sql interface. It is based on:
|
|
|
|
|
2020-07-23 04:40:32 +00:00
|
|
|
- Go sqlite3 driver: https://github.com/mattn/go-sqlite3
|
2015-04-28 23:56:53 +00:00
|
|
|
- SQLite extension with AES-256 codec: https://github.com/sqlcipher/sqlcipher
|
|
|
|
- AES-256 implementation from: https://github.com/libtom/libtomcrypt
|
|
|
|
|
|
|
|
SQLite itself is part of SQLCipher.
|
|
|
|
|
2020-07-23 02:04:21 +00:00
|
|
|
### Incompatibilities of SQLCipher
|
2019-02-27 15:23:16 +00:00
|
|
|
|
2020-07-23 02:04:21 +00:00
|
|
|
The version tags of go-sqlcipher are the same as for SQLCipher.
|
|
|
|
|
|
|
|
**SQLCipher 4.x is incompatible with SQLCipher 3.x!**
|
|
|
|
|
|
|
|
go-sqlcipher does not implement any migration strategies at the moment.
|
|
|
|
So if you upgrade a major version of go-sqlcipher, you yourself are responsible
|
|
|
|
to upgrade existing database files.
|
|
|
|
|
|
|
|
See [migrating databases](https://www.zetetic.net/sqlcipher/sqlcipher-api/#Migrating_Databases) for details.
|
2015-04-28 23:56:53 +00:00
|
|
|
|
2020-07-23 02:33:59 +00:00
|
|
|
To upgrade your Go code to the 4.x series, change the import path to
|
|
|
|
|
|
|
|
"github.com/mutecomm/go-sqlcipher/v4"
|
|
|
|
|
2015-09-27 06:01:47 +00:00
|
|
|
### Installation
|
2015-04-28 23:56:53 +00:00
|
|
|
|
|
|
|
This package can be installed with the go get command:
|
|
|
|
|
|
|
|
go get github.com/mutecomm/go-sqlcipher
|
|
|
|
|
|
|
|
|
2015-09-27 06:01:47 +00:00
|
|
|
### Documentation
|
2015-04-28 23:56:53 +00:00
|
|
|
|
2015-11-30 00:02:48 +00:00
|
|
|
To create and open encrypted database files use the following DSN parameters:
|
|
|
|
|
|
|
|
```go
|
|
|
|
key := "2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99"
|
2015-11-30 01:00:07 +00:00
|
|
|
dbname := fmt.Sprintf("db?_pragma_key=x'%s'&_pragma_cipher_page_size=4096", key)
|
2015-11-30 00:02:48 +00:00
|
|
|
db, _ := sql.Open("sqlite3", dbname)
|
|
|
|
```
|
|
|
|
|
|
|
|
`_pragma_key` is the hex encoded 32 byte key (must be 64 characters long).
|
|
|
|
`_pragma_cipher_page_size` is the page size of the encrypted database (set if
|
2020-07-23 04:40:32 +00:00
|
|
|
you want a different value than the default size).
|
2015-11-30 00:02:48 +00:00
|
|
|
|
2015-04-28 23:56:53 +00:00
|
|
|
API documentation can be found here:
|
|
|
|
http://godoc.org/github.com/mutecomm/go-sqlcipher
|
|
|
|
|
2017-05-08 21:04:03 +00:00
|
|
|
Use the function
|
|
|
|
[sqlite3.IsEncrypted()](https://godoc.org/github.com/mutecomm/go-sqlcipher#IsEncrypted)
|
|
|
|
to check whether a database file is encrypted or not.
|
|
|
|
|
2015-04-28 23:56:53 +00:00
|
|
|
Examples can be found under the `./_example` directory
|
|
|
|
|
|
|
|
|
2015-09-27 06:01:47 +00:00
|
|
|
### License
|
2015-04-28 23:56:53 +00:00
|
|
|
|
|
|
|
The code of the originating packages is covered by their respective licenses.
|
2015-09-27 06:01:47 +00:00
|
|
|
See [LICENSE](LICENSE) file for details.
|