Code Monkey home page Code Monkey logo

go-sqlcipher's Introduction

go-sqlcipher

GoDoc CI

Description

Self-contained Go sqlite3 driver with an AES-256 encrypted sqlite3 database conforming to the built-in database/sql interface. It is based on:

SQLite itself is part of SQLCipher.

Incompatibilities of SQLCipher

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 for details.

To upgrade your Go code to the 4.x series, change the import path to

"github.com/Hutt0n0/go-sqlcipher"

Installation

This package can be installed with the go get command:

go get github.com/mutecomm/go-sqlcipher

Documentation

To create and open encrypted database files use the following DSN parameters:

key := "2DD29CA851E7B56E4697B0E1F08507293D761A05CE4D1B628663F411A8086D99"
dbname := fmt.Sprintf("db?_pragma_key=x'%s'&_pragma_cipher_page_size=4096", key)
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 you want a different value than the default size).

key := url.QueryEscape("secret")
dbname := fmt.Sprintf("db?_pragma_key=%s&_pragma_cipher_page_size=4096", key)
db, _ := sql.Open("sqlite3", dbname)

This uses a passphrase directly as _pragma_key with the key derivation function in SQLCipher. Do not forget the url.QueryEscape() call in your code!

See also PRAGMA key.

API documentation can be found here: http://godoc.org/github.com/mutecomm/go-sqlcipher

Use the function sqlite3.IsEncrypted() to check whether a database file is encrypted or not.

Examples can be found under the ./_example directory

2024-5-22

增加对如下查询参数的识别能力: PRAGMA cipher_use_hmac = ; PRAGMA kdf_iter = ; PRAGMA cipher_hmac_algorithm =; PRAGMA cipher_kdf_algorithm =;

	dbname := fmt.Sprintf("message.db?_pragma_key=%s"+
		"&_pragma_cipher_page_size=1024"+
		"&_pragma_cipher_use_hmac=off"+
		"&_pragma_kdf_iter=4000"+
		"&_pragma_cipher_hmac_algorithm=HMAC_SHA1"+
		"&_pragma_cipher_kdf_algorithm=PBKDF2_HMAC_SHA1", key)

License

The code of the originating packages is covered by their respective licenses. See LICENSE file for details.

go-sqlcipher's People

Contributors

frankbraun avatar hutt0n0 avatar klingtnet avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.