Documentation ¶
Index ¶
- Constants
- Variables
- func Benchmark(params ScryptParams) (seconds float64, err error)
- func CheckV2(origin, passwordStr string) bool
- func GenerateV2(origin string) string
- func GetHashVersion(ciphertext string) (version int, err error)
- func GetMasterVersion(ciphertext string) (version int, err error)
- func Hash(userpass, masterpass string, version int, ...) (pwHashOut string, err error)
- func UpdateMaster(newMaster, oldMaster string, newVersion int, ciphertext string, ...) (pwHashOut string, err error)
- func Verify(userpass, masterpass, ciphertext string) error
- type Config
- type Generator
- func (g Generator) Generate() (*string, error)
- func (g Generator) GenerateByLength(length uint) string
- func (g Generator) GenerateByOK() string
- func (g Generator) GenerateByStrong() string
- func (g Generator) GenerateByVeryStrong() string
- func (g Generator) GenerateByWeak() string
- func (g Generator) GenerateMany(amount uint) ([]string, error)
- func (g Generator) GenerateManyWithLength(amount, length uint) ([]string, error)
- func (g Generator) GenerateWithLength(length uint) (*string, error)
- type ScryptParams
Constants ¶
const ( LengthWeak uint = 6 // 弱密码长度 LengthOK uint = 12 // 一般密码长度 LengthStrong uint = 24 // 强密码长度 LengthVeryStrong uint = 36 // 高强密码长度 DefaultLetterSet = "abcdefghijklmnopqrstuvwxyz" // 默认小写字母集合 DefaultLetterAmbiguousSet = "ijlo" // 默认相似字母集合 DefaultNumberSet = "0123456789" // 默认数字集合 DefaultNumberAmbiguousSet = "01" // 默认相似数字集合 DefaultSymbolSet = "!$%^&*()_+{}:@[];'#<>?,./|\\-=?" // 默认特殊符号集合 DefaultSymbolAmbiguousSet = "<>[](){}:;'/|\\," //默认转义符号集合 )
Variables ¶
var ( // ErrCiphertextVer indicates version sub-string mismatch normally; ex. "secBoxv1" ErrCiphertextVer = errors.New("Nonmatched ciphertext version") // ErrCiphertextFormat indicates input is not in expected format ErrCiphertextFormat = errors.New("Ciphertext input format not as expected") // ErrInvalidVersionUpdate indicates new version given not oldVersion + 1 or greater ErrInvalidVersionUpdate = errors.New("Invalid new version int, new master passphrase version must be greater than previous") // ErrPassphraseHashMismatch indicates invalid passphrase for supplied ciphertext ErrPassphraseHashMismatch = errors.New("Passphrase hash does not match supplied ciphertext") // ErrPassphraseLength indicates supplied passphrase is not at least MinLength ErrPassphraseLength = errors.New("Passphrase must be at least MinLength") // ErrSecretBoxDecryptFail indicates SecretBox decryption could not be completed ErrSecretBoxDecryptFail = errors.New("SecretBox decryption failed") // ErrScryptParamN indicates ScryptParams:N out of acceptable range ErrScryptParamN = errors.New("Given Scrypt (N) cost factor out of acceptable range") // ErrScryptParamR indicates ScryptParams:r out of acceptable range ErrScryptParamR = errors.New("Given Scrypt (r) cost factor out of acceptable range") // ErrScryptParamP indicates ScryptParams:p out of acceptable range ErrScryptParamP = errors.New("Given Scrypt (p) cost factor out of acceptable range") )
var ( // DefaultConfig 默认密码配置 DefaultConfig = Config{ Length: LengthStrong, IncludeSymbols: true, IncludeNumbers: true, IncludeLowercaseLetters: true, IncludeUppercaseLetters: true, ExcludeSimilarCharacters: true, ExcludeAmbiguousCharacters: true, } // ErrConfigIsEmpty 密码配置为空错误 ErrConfigIsEmpty = errors.New("config is empty") // 默认密码生成器 DefaultGenerator = New() )
var ( // MinLength changes the minimum passphrase and master passphrase length accepted MinLength = 8 // DefaultParams defines Scrypt Parameters DefaultParams = ScryptParams{N: 16384, R: 8, P: 1} )
Functions ¶
func Benchmark ¶
func Benchmark(params ScryptParams) (seconds float64, err error)
Benchmark takes ScryptParams and returns the number of seconds elapsed as a float64 and error
func GenerateV2 ¶
GenerateV2 生成V2级别的密码 @param origin 要加密的字符串 @return 加密后的密码字符串
func GetHashVersion ¶
GetHashVersion takes ciphertext string and returns goSecretBoxPassword version as int and error.
func GetMasterVersion ¶
GetMasterVersion takes ciphertext string and returns master passphrase version as int and error.
func Hash ¶
func Hash(userpass, masterpass string, version int, userparams, masterparams ScryptParams) (pwHashOut string, err error)
Hash takes passphrase ,masterpassphrase as strings, version indicator as int, and userparams and masterparams as ScryptParams and returns up to 225 char ciphertext string and error - ex. password.Hash("password1234", "masterpassphrase", 0, ScryptParams{N: 32768, R: 16, P: 1}, DefaultParams)
func UpdateMaster ¶
func UpdateMaster(newMaster, oldMaster string, newVersion int, ciphertext string, masterparams ScryptParams) (pwHashOut string, err error)
UpdateMaster takes new master passphrase, old master passphrase as string, new version as int, cipertext as string, and new ScryptParams. It returns and updated hash output string and error.
Types ¶
type Config ¶
type Config struct { Length uint `yaml:"length" json:"length"` // 密码长度 CharacterSet string `yaml:"character_set" json:"character_set"` // 字符池子,从池子里面取密码字符 IncludeSymbols bool `yaml:"include_symbols" json:"include_symbols"` // 是否包含标志,比如!"£* IncludeNumbers bool `yaml:"include_numbers" json:"include_numbers"` // 是否包含数字 IncludeLowercaseLetters bool `yaml:"include_lowercase_letters" json:"include_lowercase_letters"` // 是否包含小写字母 IncludeUppercaseLetters bool `yaml:"include_uppercase_letters" json:"include_uppercase_letters"` // 是否包含大写字母 ExcludeSimilarCharacters bool `yaml:"exclude_similar_characters" json:"exclude_similar_characters"` // 是否包含相似的字符,比如i1jIo0 ExcludeAmbiguousCharacters bool `yaml:"exclude_ambiguous_characters" json:"exclude_ambiguous_characters"` // 是否包含特殊转义符号<>{}[]()/|\ }
Config 生成密码的配置
type Generator ¶
type Generator struct {
Config *Config
}
Generator 密码生成器
func (Generator) GenerateByLength ¶
GenerateByLength 生成指定长度的命名
func (Generator) GenerateByStrong ¶
GenerateByStrong 生成强密码
func (Generator) GenerateByVeryStrong ¶
GenerateByVeryStrong 生成超强密码
func (Generator) GenerateMany ¶
GenerateMany 批量生产密码
func (Generator) GenerateManyWithLength ¶
GenerateManyWithLength generates multiple passwords with set length
type ScryptParams ¶
ScryptParams sets the Scrypt devivation parameters used for hashing
func GetParams ¶
func GetParams(ciphertext string) (userParams, masterParams ScryptParams, err error)
GetParams takes ciphertext string, returns user and master parameters and error. This may be useful for upgrading.