Documentation
¶
Index ¶
- Constants
- func CreateHash(key string) string
- func CreateJWE(payload []byte, key []byte) (string, error)
- func DecryptWithKey(data, key string) (string, error)
- func EncryptWithKey(data, key string) (string, error)
- func GenerateDefaultOTP() string
- func GenerateOTP(digit, set int, separator string) string
- func GenerateSecureRandomNumber(numLen int) (string, error)
- func GetAuthorizationFromHeader(authstring string) (string, string)
- func GetClientIDSecretFromTokenString(jwtKey string) (string, string, error)
- func GetJWTClaimMapFromTokenString(t, JWTKey string) (jwt.MapClaims, error)
- func HashPin(pin, key1, key2 string) (string, error)
- func MD5Hash(text string) string
- func NewRandomToken() string
- func NewRandomTokenIterate(x int) string
- func PGPDecrypt(privKey, encryptedMessage string) (string, error)
- func PGPEncrypt(pubKey, message string) (string, error)
- func PGPGenerateKey(name, comment, email string) (string, string, error)
- func ParseJWE(jweString string, key []byte) ([]byte, error)
- func ParseJWEToMap(jweString string, key []byte) (map[string]string, error)
- func SHA256(s string) string
Constants ¶
const ( DEFAULT_HASH_LENGTH = 32 // DEFAULT_CPU = 32768 DEFAULT_CPU = 8192 // CPU cost, usually is 32768, higher takes more resources DEFAULT_R = 8 // Repetition , higher takes more resources, default = 8 DEFAULT_P = 1 // Permutation?, higher takes more resources, default = 1 )
const ( MAX_OTP_DIGIT = 10 // max number of otp digit in total (set * digit) MIN_OTP_DIGIT = 2 // min number of otp digit per set DEFAULT_OTP_DIGIT = 2 // default otp digit per set DEFAULT_OTP_SET = 2 // default otp set DEFAULT_OTP_SEPARATOR = "-" DEFAULT_OTP_ERROR = "7" // use if randomizer is error, then random number is always this const DEFAULT_TOKEN_ITERATION = 5 // iterate randomtoken to get long random string. Used in magic link? )
Variables ¶
This section is empty.
Functions ¶
func CreateHash ¶
Create hash key with md5 which is 128bit / 32 char Can be used for AES key encryption
func EncryptWithKey ¶
func GenerateDefaultOTP ¶
func GenerateDefaultOTP() string
func GenerateOTP ¶
Get random number for OTP (6 digit format with dash) Ex: 57-03
func GenerateSecureRandomNumber ¶
GenerateSecureRandomNumber generates a secure random number of the specified number of digits.
func GetAuthorizationFromHeader ¶
Header: Authorization bearer [token] the authstring passed is the "bearer [token]" This is basically splitting the string only. Get authorization from header, return: Bearer 'token'
func GetClientIDSecretFromTokenString ¶
From Authorization : Basic [This part is JWTKey] Format accepted is JWTKey == base64(ID:SECRET) Authorization Basic JWTKey
func GetJWTClaimMapFromTokenString ¶
Get JWT Claim manually (without using the JWT middleware) Parse the header manually then get the JWT. This function is needed to check if JWT is valid but expired, then we use it to renew/extends the expiration
func HashPin ¶
Encrypt Meda password Password is in variable pin key1 and key2 is the salt. Usually key1 = signature and key2 = the additional randomness but that cannot change, usually is the created_at date string
func NewRandomToken ¶
func NewRandomToken() string
Generate just random token which is essentially a short-uuid, 22 characters length (this golang implementation) But actually short-uuid can be different length on different implementation or different programming language While standard UUID format is always 36 characters long. Also this is base57 encoding which exclude characters that is simmilar like 0 and O and l and I
func NewRandomTokenIterate ¶
Concatenante NewRandomToken (which is short-uuid) x number of times. This is to be used in maybe magic link or public link which takes longer string.
func PGPDecrypt ¶
Decrypt decrypts a message using the recipient's private key
func PGPEncrypt ¶
Encrypt encrypts a message using the recipient's public key
func PGPGenerateKey ¶
GenerateKey generates a PGP key pair and returns the public and private keys as strings
func ParseJWEToMap ¶
If the cypertext or basically the payload is json of map[string]string then this has the unmarshall NOTE: later if needed use MapToStruct from utils
Types ¶
This section is empty.