-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Crypt Encoder
Crypt Encoders are used for username and password encryption within SQLite3 when the User Authentication module is compiled in.
Go-SQLite3
comes default with several crypt encoders.
Encoder | Description |
---|---|
sha1 | SHA1 Encoder |
ssha1 | Salted SHA1 Encoder |
sha256 | SHA256 Encoder |
ssha256 | Salted SHA256 Encoder |
sha384 | SHA384 Encoder |
ssha384 | Salted SHA384 Encoder |
sha512 | SHA512 Encoder |
ssha512 | Salted SHA512 Encoder |
There are 2 interfaces available for creating your own Crypt Encoder
.
type CryptEncoder interface {
fmt.Stringer
Encode(pass []byte, hash interface{}) []byte
}
type CryptSaltedEncoder interface {
CryptEncoder
Salt() string
}
The CryptEncoder
interface is to be used when you do not require any kind of salt. And the CryptSaltedEncoder
is used when you want to use a salt within your encryption.
After you have implemented a CryptEncoder
you need to register it with the Go-SQLite3
driver so it can be found when you refer to the CryptEncoder
through the crypt
DSN key.
The key which is used in the DSN is the string
representation of the CryptEncoder
. This is the reason the fmt.Stringer
interface is enforced.
Registration of a CryptEncoder
can be done with the public function
RegisterCryptEncoder(e CryptEncoder)
After which the driver can find your custom encoder when you want it use it from a DSN.
For more information please see the source code of crypt.go and look at the default available encoders.