Documentation
¶
Overview ¶
Package security provides tools for secure data storage and transitions. Security allows to easily encode and decode data to base62 format, hash data and validate hash, create and parse JWT.
Index ¶
- func Decode(encoded string) ([]byte, error)
- func Encode(data []byte) string
- func GenerateJWT(value any, secretKey string, ttl time.Duration, algorithm string, ...) (string, error)
- func Hash(value string, hashCost int) (string, error)
- func ParseJWT(tokenString, secretKey string, opts ...jwt.ParserOption) (any, error)
- func RawDecode(encoded string) ([]byte, error)
- func RawEncode(data []byte) string
- func ValidateHash(value, hashedValue string) bool
- type Config
- type InvalidJWTError
- type JWTClaimsError
- type JWTConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateJWT ¶
func GenerateJWT( value any, secretKey string, ttl time.Duration, algorithm string, opts ...jwt.TokenOption, ) (string, error)
GenerateJWT creates a new Json Web Token, based on provided data.
value - any value to store in JWT payload;
secretKey - is a secret, on base of which will be checked, if JWT can be trusted;
ttl - time JWT is appropriate and after which will be expired;
algorithm - JWT hashing algorithm like HS256 and so on.
func Hash ¶
Hash hashes data for security purpose. For example, not to store raw unprotected data on database.
func ParseJWT ¶
func ParseJWT(tokenString, secretKey string, opts ...jwt.ParserOption) (any, error)
ParseJWT decodes a Json Web Token payload.
tokenString - a JWT, which will be parsed;
secretKey - is a secret, on base of which will be checked, if JWT can be trusted;.
func RawEncode ¶ added in v1.1.3
RawEncode encodes data for security purpose without padding characters. For example, to send in s3.
func ValidateHash ¶
ValidateHash checks if hashed data is equal to raw data.
Types ¶
type InvalidJWTError ¶
InvalidJWTError is an error, which represents, that JWT expired or something else went wrong via parsing it.
func (InvalidJWTError) Error ¶
func (e InvalidJWTError) Error() string
func (InvalidJWTError) Unwrap ¶ added in v1.2.11
func (e InvalidJWTError) Unwrap() error
type JWTClaimsError ¶
JWTClaimsError is an error, which represents, that failed to retrieve JWT payload.
func (JWTClaimsError) Error ¶
func (e JWTClaimsError) Error() string
func (JWTClaimsError) Unwrap ¶ added in v1.2.11
func (e JWTClaimsError) Unwrap() error