encryption

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 21 Imported by: 2

Documentation

Index

Constants

View Source
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
)
View Source
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

func CreateHash(key string) string

Create hash key with md5 which is 128bit / 32 char Can be used for AES key encryption

func CreateJWE

func CreateJWE(payload []byte, key []byte) (string, error)

func DecryptWithKey

func DecryptWithKey(data, key string) (string, error)

Decrypt login payload

func EncryptWithKey

func EncryptWithKey(data, key string) (string, error)

func GenerateDefaultOTP

func GenerateDefaultOTP() string

func GenerateOTP

func GenerateOTP(digit, set int, separator string) string

Get random number for OTP (6 digit format with dash) Ex: 57-03

func GenerateSecureRandomNumber

func GenerateSecureRandomNumber(numLen int) (string, error)

GenerateSecureRandomNumber generates a secure random number of the specified number of digits.

func GetAuthorizationFromHeader

func GetAuthorizationFromHeader(authstring string) (string, string)

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

func GetClientIDSecretFromTokenString(jwtKey string) (string, string, error)

From Authorization : Basic [This part is JWTKey] Format accepted is JWTKey == base64(ID:SECRET) Authorization Basic JWTKey

func GetJWTClaimMapFromTokenString

func GetJWTClaimMapFromTokenString(t, JWTKey string) (jwt.MapClaims, error)

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

func HashPin(pin, key1, key2 string) (string, error)

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 MD5Hash

func MD5Hash(text string) 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

func NewRandomTokenIterate(x int) string

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

func PGPDecrypt(privKey, encryptedMessage string) (string, error)

Decrypt decrypts a message using the recipient's private key

func PGPEncrypt

func PGPEncrypt(pubKey, message string) (string, error)

Encrypt encrypts a message using the recipient's public key

func PGPGenerateKey

func PGPGenerateKey(name, comment, email string) (string, string, error)

GenerateKey generates a PGP key pair and returns the public and private keys as strings

func ParseJWE

func ParseJWE(jweString string, key []byte) ([]byte, error)

Parse JWE token

func ParseJWEToMap

func ParseJWEToMap(jweString string, key []byte) (map[string]string, error)

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

func SHA256

func SHA256(s string) string

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL