ubsecurity

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Security related tools.

Index

Constants

This section is empty.

Variables

View Source
var DefaultArgon2Id = Argon2IdHashGenerator{
	Memory:      64 * 1024,
	Iterations:  3,
	Parallelism: 2,
	SaltLength:  16,
	Keylength:   32,
	Pepper:      nil,
}

An Argon2IdHashGenerator with default settings which can be used as is.

Functions

func Decrypt

func Decrypt(key []byte, data []byte) ([]byte, error)

func Decrypt64

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

func Encrypt

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

func Encrypt64

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

func GenerateSecureRandom

func GenerateSecureRandom(length uint32) []byte

Utility to generate a secure random bytes.

func GenerateSecureRandomString added in v0.0.7

func GenerateSecureRandomString(length uint32) string

func GenerateSecureRandomStringWithChars added in v0.0.7

func GenerateSecureRandomStringWithChars(length uint32, chars []rune) string

Types

type Argon2IdHashGenerator

type Argon2IdHashGenerator struct {
	// Amount of memory to use
	Memory uint32

	// Number of argon2id iterations
	Iterations uint32

	// Amount of threads or parallelism.
	Parallelism uint8

	// Length of the salt.
	SaltLength uint32

	// Length of the resulting key.
	Keylength uint32

	// If set, this value is appended to the password/target before hashing.
	Pepper []byte
}

Use to generate hashes using argon2id.

func (Argon2IdHashGenerator) GenerateHashBase64

func (i Argon2IdHashGenerator) GenerateHashBase64(target string) (string, error)

Generates the hash of a string and returns the base64 encoded hash.

func (Argon2IdHashGenerator) GenerateHashBytes

func (i Argon2IdHashGenerator) GenerateHashBytes(target string) []byte

Generates a hash of the specified string.

func (Argon2IdHashGenerator) GenerateHashWithSalt

func (i Argon2IdHashGenerator) GenerateHashWithSalt(targetBytes []byte, saltBytes []byte) []byte

Genrate bytes with the specified salt. The salt is the first n bytes of the returned value

func (Argon2IdHashGenerator) GenerateKeyFromBytes

func (i Argon2IdHashGenerator) GenerateKeyFromBytes(targetBytes []byte, length uint32, saltBytes []byte) []byte

Generates the raw hash without including the salt in the output bytes.

func (Argon2IdHashGenerator) Verify

func (i Argon2IdHashGenerator) Verify(target []byte, hashed []byte) bool

Verifies the specified target bytes against the hash.

func (Argon2IdHashGenerator) VerifyBase64

func (i Argon2IdHashGenerator) VerifyBase64(target string, base64Hash string) (bool, error)

Verifies the specified target against a hash encoded in base64.

type EncryptionService

type EncryptionService interface {
	Encrypt(data []byte) ([]byte, error)
	Decrypt(data []byte) ([]byte, error)
	Encrypt64(data string) (string, error)
	Decrypt64(data string) ([]byte, error)
}

func NewEncryptionService added in v0.0.7

func NewEncryptionService(key []byte) EncryptionService

type EncryptionServiceImpl added in v0.0.7

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

func (EncryptionServiceImpl) Decrypt added in v0.0.7

func (s EncryptionServiceImpl) Decrypt(data []byte) ([]byte, error)

func (EncryptionServiceImpl) Decrypt64 added in v0.0.7

func (s EncryptionServiceImpl) Decrypt64(data string) ([]byte, error)

func (EncryptionServiceImpl) Encrypt added in v0.0.7

func (s EncryptionServiceImpl) Encrypt(data []byte) ([]byte, error)

func (EncryptionServiceImpl) Encrypt64 added in v0.0.7

func (s EncryptionServiceImpl) Encrypt64(data string) (string, error)

type HashGenerator

type HashGenerator interface {
	GenerateHashBytes(string) []byte
	GenerateHashBase64(string) (string, error)
	VerifyBase64(string, string) (bool, error)
	Verify([]byte, []byte) bool
}

Base interface for hash generators.

Jump to

Keyboard shortcuts

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