Documentation ¶
Index ¶
- func Argon2idHashPassword(password string) (string, error)
- func BcryptCheckPasswordHash(password, hash string) bool
- func BcryptHashPassword(password string) (string, error)
- func GenerateJWTFile(jwtClaims jwt.Claims, filePath string) (string, error)
- func GenerateOTP(length int) string
- func GenerateRandomString(length int) string
- func GenerateSecureToken(length int) (string, error)
- func GenerateToken64() string
- func HashSHA256(input string) string
- func NewHs256AccessToken(claims UserClaims) (string, error)
- func NewHs256RefreshToken(claims jwt.StandardClaims) (string, error)
- func ParseHs256RefreshToken(refreshToken string) *jwt.StandardClaims
- func RetryGenerateSecureToken(length int, retries int) (string, error)
- func ValidateJWT(tokenString string) (jwt.MapClaims, error)
- func ValidateRSAKeyPair(keyPair PublicPrivatePair) (bool, error)
- func VerifySHA256(input, hashedValue string) bool
- type GenerateJwt
- type PublicPrivatePair
- type UserClaims
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Argon2idHashPassword ¶
Argon2idHashPassword generates an Argon2id hash from the provided password. It uses a cryptographically secure random salt and configurable parameters for iterations, memory, parallelism, and key length to generate the hash. The generated hash is encoded in a string format containing information about the hash parameters and the encoded hash itself.
Parameters:
password: The plaintext password to be hashed.
Returns:
string: The hashed password encoded in a string format containing hash parameters. error: An error, if any, encountered during the hashing process.
func BcryptCheckPasswordHash ¶
func BcryptHashPassword ¶
BcryptHashPassword generates a bcrypt hash from the provided password using a cost factor of 12. It returns the hashed password as a string.
Parameters:
password: The plaintext password to be hashed.
Returns:
string: The hashed password. error: An error, if any, encountered during the hashing process.
func GenerateJWTFile ¶
GenerateJWTFile generates a JWT token using a private key
func GenerateOTP ¶
GenerateOTP generates a random One-Time Password (OTP) of the specified length. It uses a cryptographically secure random number generator to ensure the randomness of the generated OTP.
Parameters:
length: The length of the OTP to be generated.
Returns:
string: The randomly generated OTP.
func GenerateRandomString ¶
GenerateRandomString generates a random string of the specified length. It utilizes a pseudo-random number generator seeded with the current time to ensure randomness in the generated string.
Parameters:
length: The length of the random string to be generated.
Returns:
string: The randomly generated string.
func GenerateSecureToken ¶
GenerateSecureToken generates a secure token of the specified length. It utilizes the cryptographic randomness provided by the rand package to ensure the security and unpredictability of the generated token.
Parameters:
length: The length of the secure token to be generated.
Returns:
string: The randomly generated secure token in hexadecimal format. error: An error, if any, encountered during the token generation process.
func GenerateToken64 ¶
func GenerateToken64() string
func HashSHA256 ¶
HashSHA256 hashes the input string using SHA-256 algorithm.
Parameters:
input (string): The input string to be hashed.
Returns:
string: The hexadecimal representation of the hashed value.
func NewHs256AccessToken ¶
func NewHs256AccessToken(claims UserClaims) (string, error)
func NewHs256RefreshToken ¶
func NewHs256RefreshToken(claims jwt.StandardClaims) (string, error)
func ParseHs256RefreshToken ¶
func ParseHs256RefreshToken(refreshToken string) *jwt.StandardClaims
func ValidateJWT ¶
ValidateJWT validates a JWT token using a public key
func ValidateRSAKeyPair ¶
func ValidateRSAKeyPair(keyPair PublicPrivatePair) (bool, error)
ValidateRSAKeyPair validates an RSA key pair by encrypting and decrypting a message. It returns true if the validation succeeds, indicating that the key pair is valid. Otherwise, it returns false.
Parameters:
keyPair: The RSA public and private keys encoded in PEM format.
Returns:
bool: A boolean indicating whether the key pair is valid. error: An error, if any, encountered during the validation process.
func VerifySHA256 ¶
VerifySHA256 verifies if the input matches the hashed value.
Parameters:
input (string): The input string to be verified. hashedValue (string): The hashed value to be compared with the hashed input.
Returns:
bool: Returns true if the input matches the hashed value; otherwise, returns false.
Types ¶
type GenerateJwt ¶
type PublicPrivatePair ¶
func GenerateRSAKeyPair ¶
func GenerateRSAKeyPair() (PublicPrivatePair, error)
GenerateRSAKeyPair generates a pair of RSA public and private keys with a key size of 2048 bits. It returns the public and private keys encoded in PEM format.
Returns:
PublicPrivatePair: A struct containing the RSA public and private keys error: An error, if any, encountered during the key pair generation process.
type UserClaims ¶
type UserClaims struct { First string `json:"first"` Last string `json:"last"` Token string `json:"token"` jwt.StandardClaims }
func ParseHs256AccessToken ¶
func ParseHs256AccessToken(accessToken string) (*UserClaims, error)