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, signingKey string, duration time.Duration) (string, error)
- func ParseJWT(token string, verificationKey string) (jwt.MapClaims, error)
- func ParseUnverifiedJWT(token string) (jwt.MapClaims, error)
- func PseudorandomString(length int) string
- func PseudorandomStringWithAlphabet(length int, alphabet string) string
- func RandomString(length int) string
- func RandomStringByRegex(pattern string, optFlags ...syntax.Flags) (string, error)
- 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).
This method uses AES-256-GCM block cypher mode.
func Encrypt ¶
Encrypt encrypts "data" with the specified "key" (must be valid 32 char AES key).
This method uses AES-256-GCM block cypher mode.
func Equal ¶ added in v0.18.2
Equal compares two hash strings for equality without leaking timing information.
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 ¶ added in v0.8.0
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 ¶ added in v0.8.0
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 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 RandomStringByRegex ¶ added in v0.23.0
RandomStringByRegex generates a random string matching the regex pattern. If optFlags is not set, fallbacks to syntax.Perl.
NB! While the source of the randomness comes from crypto/rand this method is not recommended to be used on its own in critical secure contexts because the generated length could vary too much on the used pattern and may not be as secure as simply calling security.RandomString. If you still insist on using it for such purposes, consider at least a large enough minimum length for the generated string, e.g. `[a-z0-9]{30}`.
This function is inspired by github.com/pipe01/revregexp, github.com/lucasjones/reggen and other similar packages.
func RandomStringWithAlphabet ¶ added in v0.5.0
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.
Types ¶
This section is empty.