cryptography

package
v0.0.0-...-167b7d5 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CodeChallengeMethodPlain = "plain"
	CodeChallengeMethodS256  = "S256"
)
View Source
const (
	DefaultCypherCost = 6 // recommended value for non admin users
)

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

CheckPasswordHash compares a password with a hash and returns true if they match

func Decryptb

func Decryptb(key, text []byte) ([]byte, error)

func Decrypts

func Decrypts(key, text string) (string, error)

func Encryptb

func Encryptb(key, text []byte) ([]byte, error)

func Encrypts

func Encrypts(key, text string) (string, error)

func FixKey

func FixKey(key []byte) []byte

func GenerateCodeChallenge

func GenerateCodeChallenge(method, codeVerifier string) (string, error)

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes a password with the default cypher cost

func LoadPrivateKey

func LoadPrivateKey(path string) (*rsa.PrivateKey, error)

func RandomPassword

func RandomPassword(length int) (string, error)

RandomPassword generates a random password of the specified length

func SHA256

func SHA256(text string) string

func SHA256b

func SHA256b(bytes []byte) []byte

Types

type Keypair

type Keypair struct {
	PrivateKey *rsa.PrivateKey
	PublicKey  *rsa.PublicKey
	Kid        string
}

Keypair is an RSA Keypair & JWT KeyID used for OIDC Token signing

func NewKeypair

func NewKeypair(key *rsa.PrivateKey) (*Keypair, error)

NewKeypair makes a Keypair off the provided rsa.PrivateKey or returns the package default if nil was passed

func (*Keypair) KeyID

func (k *Keypair) KeyID() (string, error)

If not manually set, computes the JWT headers' `kid`

func (*Keypair) SignJWT

func (k *Keypair) SignJWT(claims jwt.Claims) (string, error)

SignJWT signs jwt.Claims with the Keypair and returns a token string

func (*Keypair) VerifyJWT

func (k *Keypair) VerifyJWT(token string) (*jwt.Token, error)

VerifyJWT verifies the signature of a token was signed with this Keypair

type TOTP

type TOTP struct {
	// contains filtered or unexported fields
}

/ The specifications for this are found in RFC 6238 / http://tools.ietf.org/html/rfc6238

func NewTOTP

func NewTOTP(secret string, step, digits int) *TOTP

NewTOTP creates a new TOTP instance with the provided parameters.

func NewTOTPDefault

func NewTOTPDefault(secret string) *TOTP

func (*TOTP) Compute

func (t *TOTP) Compute() string

Compute generates a TOTP code based on the current time.

func (*TOTP) ComputeAt

func (t *TOTP) ComputeAt(time time.Time) string

func (*TOTP) Uri

func (t *TOTP) Uri(issuer, account string) string

func (*TOTP) Verify

func (t *TOTP) Verify(valueToVerify string, from, to int) bool

Verify checks if the provided valueToVerify is a valid TOTP code for the current time or a time range.

func (*TOTP) VerifyAt

func (t *TOTP) VerifyAt(valueToVerify string, time time.Time, from, to int) bool

Jump to

Keyboard shortcuts

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