keygen

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package keygen provides functionality for generating API client IDs and secrets

Index

Constants

View Source
const (
	KeyIDLength  = 32
	SecretLength = 64
	ByteLength   = 8
)

Defaults for the length of key IDs and secrets in Datum

Variables

This section is empty.

Functions

func Alpha

func Alpha(n int) string

Alpha generates a random string of n characters that only includes upper and lowercase letters (no symbols or digits)

func AlphaNumeric

func AlphaNumeric(n int) string

AlphaNumeric generates a random string of n characters that includes upper and lowercase letters and the digits 0-9

func CryptoRandInt

func CryptoRandInt() uint64

CryptoRandInt function generates a random 64-bit unsigned integer using cryptographic methods

func Decrypt added in v0.2.5

func Decrypt(cipherText string, key string) ([]byte, error)

Decrypt decrypts encrypted text with key (must be valid 32 chars aes key).

func Encrypt added in v0.2.5

func Encrypt(data []byte, key string) (string, error)

Encrypt encrypts data with key (must be valid 32 char aes key).

func Equal added in v0.2.5

func Equal(hash1 string, hash2 string) bool

Equal compares two hash strings for equality without leaking timing information

func GenerateRandomBytes added in v0.2.5

func GenerateRandomBytes(size int) []byte

GenerateRandomBytes returns random bytes

func GenerateRandomString added in v0.2.5

func GenerateRandomString(size int) string

GenerateRandomString returns a random string

func GenerateRandomStringHex added in v0.2.5

func GenerateRandomStringHex(size int) string

GenerateRandomStringHex returns a random hexadecimal string

func GenerateSHA256Hmac added in v0.2.5

func GenerateSHA256Hmac(secret string, data []byte) string

GenerateSHA256Hmac generates a SHA-256 HMAC by using the secret as the key and the data as the message

func HS256 added in v0.2.5

func HS256(text string, secret string) string

HS256 creates a HMAC hash with sha256 digest algorithm.

func HS512 added in v0.2.5

func HS512(text string, secret string) string

HS512 creates a HMAC hash with sha512 digest algorithm

func Hash added in v0.2.5

func Hash(value string) string

Hash returns a SHA-256 checksum of a string

func HashFromBytes added in v0.2.5

func HashFromBytes(value []byte) string

HashFromBytes returns a SHA-256 checksum of the input

func HashInput added in v0.2.5

func HashInput(input string) (string, error)

HashInput function takes an input and generates a bcrypt hash

func KeyID

func KeyID() string

KeyID returns a random ID that is of a fixed length with only alpha characters

func PrefixedSecret added in v0.3.3

func PrefixedSecret(prefix string) string

PrefixedSecret returns a prefixed random string of a fixed length with alpha-numeric characters

func S256Challenge added in v0.2.5

func S256Challenge(code string) string

S256Challenge creates [RFC 7636]: https://datatracker.ietf.org/doc/html/rfc7636#section-4.2

func SHA256 added in v0.2.5

func SHA256(text string) string

SHA256 creates sha256 hash as defined in FIPS 180-4

func SHA512 added in v0.2.5

func SHA512(text string) string

SHA512 creates sha512 hash as defined in FIPS 180-4

func Secret

func Secret() string

Secret returns a random string of a fixed length with alpha-numeric characters

Types

This section is empty.

Jump to

Keyboard shortcuts

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