Documentation ¶
Index ¶
- func Decrypt(cipherText string, key string) ([]byte, error)
- func Encrypt(data []byte, key string) (string, error)
- func Equal(hash1 string, hash2 string) bool
- func HS256(text string, secret string) string
- func HS512(text string, secret string) string
- func MD5(text string) string
- func NewJWT(payload jwt.MapClaims, oldSigninKey string, secondsDuration int64) (string, error)
- func NewToken(payload jwt.MapClaims, signingKey string, secondsDuration int64) (string, error)deprecated
- func ParseJWT(token string, oldVerificationKey string) (jwt.MapClaims, error)
- func ParseUnverifiedJWT(token string) (jwt.MapClaims, error)
- func PseudorandomString(length int) string
- func PseudorandomStringWithAlphabet(length int, alphabet string) string
- func RandomSnowflakeId() string
- func RandomString(length int) string
- func RandomStringWithAlphabet(length int, alphabet string) string
- func S256Challenge(code string) string
- func SHA256(text string) string
- func SHA512(text string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decrypt ¶
Decrypt decrypts encrypted text with key (must be valid 32 chars aes key).
func Encrypt ¶
Encrypt encrypts data with key (must be valid 32 char aes key).
func Equal ¶
Equal compares two hash strings for equality without leaking timing information.
func HS256 ¶
HS256 creates a HMAC hash with sha256 digest algorithm.
func HS512 ¶
HS512 creates a HMAC hash with sha512 digest algorithm.
func NewJWT ¶
NewJWT generates and returns new HS256 signed JWT.
func ParseJWT ¶
ParseJWT verifies and parses JWT and returns its claims.
func ParseUnverifiedJWT ¶
ParseUnverifiedJWT parses JWT and returns its claims but DOES NOT verify the signature.
It verifies only the exp, iat and nbf claims.
func PseudorandomString ¶
PseudorandomString generates a pseudorandom string with the specified length.
The generated string matches [A-Za-z0-9]+ and it's transparent to URL-encoding.
For a cryptographically random string (but a little bit slower) use RandomString instead.
func PseudorandomStringWithAlphabet ¶
PseudorandomStringWithAlphabet generates a pseudorandom string with the specified length and characters set.
For a cryptographically random (but a little bit slower) use RandomStringWithAlphabet instead.
func RandomSnowflakeId ¶
func RandomSnowflakeId() string
RandomSnowflakeId generates a snowflake id.
The generated id is a string like "1537200202186752" 16-20 characters length.
func RandomString ¶
RandomString generates a cryptographically random string with the specified length.
The generated string matches [A-Za-z0-9]+ and it's transparent to URL-encoding.
func RandomStringWithAlphabet ¶
RandomStringWithAlphabet generates a cryptographically random string with the specified length and characters set.
It panics if for some reason rand.Int returns a non-nil error.
func S256Challenge ¶
S256Challenge creates base64 encoded sha256 challenge string derived from code. The padding of the result base64 string is stripped per RFC 7636.
func SHA256 ¶
SHA256 creates sha256 hash as defined in FIPS 180-4 from the provided text.
Types ¶
This section is empty.