Documentation ¶
Index ¶
- Constants
- Variables
- func AesCtrDecrypt(key []byte, msg []byte) ([]byte, error)
- func AesCtrDecryptBase64(key []byte, msg string) (inp []byte, err error)
- func AesCtrEncrypt(key []byte, msg []byte) ([]byte, error)
- func AesCtrEncryptBase64(key []byte, msg []byte) (b64 string, err error)
- func AesGcmDecrypt(key []byte, msg []byte) ([]byte, error)
- func AesGcmDecryptBase64(key []byte, msg string) (inp []byte, err error)
- func AesGcmEncrypt(key []byte, msg []byte) ([]byte, error)
- func AesGcmEncryptBase64(key []byte, msg []byte) (b64 string, err error)
- func GenPassword(l int) string
- func GenRandomBase64String(l int) string
- func GenRandomBytes(l int) (rb []byte)
- func GenRandomHexString(l int) string
- func GenRandomString(l int) string
- func GenSessionID(l ...int) string
- func GenSessionIDBase32(l ...int) string
- func VerifyPassword(hashstr, pwd string) (ok bool)
- func VerifyPasswordGetMeta(hashstr, pwd string) (bool, uint8, int8, uint8)
- type AuthPassword
- type AuthPasswordConfig
- type CSRFGate
- type CSRFGateConfig
- type CSRFRequestBody
Constants ¶
const ( //dSecurityKey = "\x69\x51\xe8\x41\x50\x83\x19\xa4\xf0\x2f\xac\x7d\x99\xb7\x5e\xbe\x7e\x32\xf5\xa5\xf7\x1f\x43\x04\x96\xdd\x1b\xf0\x93\x4e\xc5\x44" //dCSRFToken = "\xc7\x58\xa7\xf2\x15\x79\x54\x34\x24\xeb\x45\x50\x33\x0f\xa5\x52\x95\x36\x06\xb0\xb7\xdb\x5d\xa7\x07\xcf\xa5\x1c\x10\xe7\x4b\xd4" //dHashSalt = "\x5d\xfb\xcf\x47\x30\xce\x2e\x43\xfa\x1c\x5f\xee\x76\x0f\xd7\x31\x14\x07\x24\xa8\xbf\xd0\x3c\x88\xfc\xa3\xdc\x3b\xae\xaa\x3a\x15" //dCSRFTokenLife = 14400 CSRFTokenMinLife = 3600 CSRFDefaultTokenLife = 14400 CSRFDefaultCookieName = "XSRF-TOKEN" CSRFDefaultRequestName = "X-XSRF-TOKEN" CSRFTimestampLen = 5 CSRFRandTokenLen = 16 )
const DefaultSaltLen = 24
Variables ¶
var ( ErrNonceGenFailed = errors.New("generating of random nonce failed") ErrNonceMissing = errors.New("unable to locate nonce in encrypted message") )
var ErrSaltGenFailed = errors.New("unable to generate a random salt")
Functions ¶
func AesCtrDecrypt ¶
AesCtrDecrypt decrypts the given encrypted msg with the key using AES CTR cipher, and returns the decrypted slice of bytes or error if any
func AesCtrDecryptBase64 ¶
AesCtrDecryptBase64 decrypts the given encrypted msg of base64 format with the key using AES GCM cipher, and returns the decrypted slice of bytes or error if any
func AesCtrEncrypt ¶
AesCtrEncrypt encrypts the given msg with the key using AES CTR cipher, and returns the encrypted slice of bytes or error if any
func AesCtrEncryptBase64 ¶
AesCtrEncryptBase64 encrypts the given msg with the key using AES CTR cipher, and returns the base64 string format of the encrypted bytes or error if any
func AesGcmDecrypt ¶
AesGcmDecrypt decrypts the given encrypted msg with the key using AES GCM cipher, and returns the decrypted slice of bytes or error if any
func AesGcmDecryptBase64 ¶
AesGcmDecryptBase64 decrypts the given encrypted msg of base64 format with the key using AES GCM cipher, and returns the decrypted slice of bytes or error if any
func AesGcmEncrypt ¶
AesGcmEncrypt encrypts the given msg with the key using AES GCM cipher, and returns the encrypted slice of bytes or error if any
func AesGcmEncryptBase64 ¶
AesGcmEncryptBase64 encrypts the given msg with the key using AES GCM cipher, and returns the base64 string format of the encrypted bytes or error if any
func GenPassword ¶
func GenRandomBase64String ¶
func GenRandomBytes ¶
GenRandomBytes return a slice of random bytes of length l
func GenRandomHexString ¶
func GenRandomString ¶
func GenSessionID ¶
func GenSessionIDBase32 ¶
func VerifyPassword ¶
Types ¶
type AuthPassword ¶
type AuthPassword struct {
// contains filtered or unexported fields
}
func NewAuthPassword ¶
func NewAuthPassword(settings AuthPasswordConfig) *AuthPassword
func (*AuthPassword) CryptPassword ¶
func (ap *AuthPassword) CryptPassword(pwd string) (string, error)
func (*AuthPassword) HashIsOutdated ¶
func (ap *AuthPassword) HashIsOutdated(hashstr string) bool
func (*AuthPassword) VerifyPassword ¶
func (ap *AuthPassword) VerifyPassword(hashstr, pwd string) bool
func (*AuthPassword) VerifyPasswordAndUpdateHash ¶
func (ap *AuthPassword) VerifyPasswordAndUpdateHash(hashstr, pwd string) (bool, string)
when crypto is updated, the hash done using previous crypto can still be verified and the new hash with the updated crypto will be returned this allows rolling updates of new crypto hash function for password hashing
type AuthPasswordConfig ¶
type CSRFGate ¶
type CSRFGate struct {
// contains filtered or unexported fields
}
func NewCSRFGate ¶
func NewCSRFGate(settings CSRFGateConfig) *CSRFGate
func (*CSRFGate) CSRFToken ¶
func (cg *CSRFGate) CSRFToken(w http.ResponseWriter, r *http.Request) (crb CSRFRequestBody)
SetCSRFToken returns a CsrfRequestBody containing the name and value to be used as a query string or form input that can be verified by VerifyCSRFToken. Additionally, a cookie will be set (if ResponseWriter is not nil) to cross authenticate validity of token data if non exists