Documentation ¶
Index ¶
- Constants
- Variables
- func CreatePasswd(length int, kind string) string
- type Encryptor
- func (e *Encryptor) Decrypt(ciphertext string) (string, error)
- func (e *Encryptor) DecryptSymmetric(ciphertext string) (string, error)
- func (e *Encryptor) Encrypt(plaintext string) (string, error)
- func (e *Encryptor) EncryptSymmetric(plaintext string) (string, error)
- func (e *Encryptor) ReplaceCharacters(plaintext string) string
- func (e *Encryptor) RestoreCharacters(ciphertext string) string
- type MD5Password
- type OptionFunc
- type SCRAMPassword
Constants ¶
const ( // 密码生成类型 CreatePWDWithNum = "num" CreatePWDWithChar = "char" CreatePWDWithMix = "mix" CreatePWDWithAdvance = "advance" )
Variables ¶
var ( // ErrSCRAMPasswordInvalid is returned when the password attributes are invalid ErrSCRAMPasswordInvalid = errors.New(`invalid password attributes. must provide "password"`) // ErrSCRAMSaltLengthInvalid is returned when the salt length is less than 1 ErrSCRAMSaltLengthInvalid = errors.New(`salt length must be at least 1`) )
var DefaultEncryptor = Encryptor{ // contains filtered or unexported fields }
var ErrMD5PasswordInvalid = errors.New(`invalid password attributes. must provide "username" and "password"`)
ErrMD5PasswordInvalid is returned when the password attributes are invalid
Functions ¶
func CreatePasswd ¶
Types ¶
type Encryptor ¶
type Encryptor struct {
// contains filtered or unexported fields
}
func NewEncryptor ¶
func NewEncryptor(opts ...OptionFunc) *Encryptor
func (*Encryptor) DecryptSymmetric ¶
对密文进行对称解密
func (*Encryptor) EncryptSymmetric ¶
对明文进行对称加密
func (*Encryptor) ReplaceCharacters ¶
对明文进行字符替换
func (*Encryptor) RestoreCharacters ¶
对密文进行字符替换
type MD5Password ¶
type MD5Password struct {
// contains filtered or unexported fields
}
MD5Password implements the PostgresPassword interface for hashing passwords using the PostgreSQL MD5 method
func NewMD5Password ¶
func NewMD5Password(username, password string) *MD5Password
NewMD5Password constructs a new MD5Password struct
func (*MD5Password) Build ¶
func (m *MD5Password) Build() (string, error)
Build creates the MD5 password format for PostgreSQL which resembles "md5" + md5("password" + "username")
type OptionFunc ¶
type OptionFunc func(o *Encryptor)
Option is an application option.
func Algorithm ¶
func Algorithm(algorithm string) OptionFunc
func Iv ¶
func Iv(iv string) OptionFunc
func Key ¶
func Key(key string) OptionFunc
func ReplaceTable ¶
func ReplaceTable(replaceTable string) OptionFunc
func ReplaceWith ¶
func ReplaceWith(replaceWith string) OptionFunc
type SCRAMPassword ¶
type SCRAMPassword struct { // Iterations is the number of iterations to run the PBKDF2 algorithm when // generating the hashed salted password. This defaults to 4096, which is the // PostgreSQL default Iterations int // SaltLength is the length of the generated salt that is used as part of the // PBKDF2 algorithm SaltLength int // contains filtered or unexported fields }
SCRAMPassword contains the building blocks to build a PostgreSQL SCRAM verifier. Implements the PostgresPassword interface
func NewSCRAMPassword ¶
func NewSCRAMPassword(password string) *SCRAMPassword
NewSCRAMPassword constructs a new SCRAMPassword struct with sane defaults
func (*SCRAMPassword) Build ¶
func (s *SCRAMPassword) Build() (string, error)
Build creates the SCRAM verifier, which follows the methods defined in the PostgreSQL source, i.e.
https://git.postgresql.org/gitweb/?p=postgresql.git;a=blob;f=src/include/common/scram-common.h