symutils

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustRandomString added in v0.5.0

func MustRandomString(keyLen int) string

MustRandomString returns a random string of len keyLen.

func NewFactoryAEAD

func NewFactoryAEAD(keyLen int, cipherFactory cipherFactoryFunc) symmecrypt.KeyFactory

NewFactoryAEAD returns a symmecrypt.KeyFactory that can be registered to symmecrypt.RegisterCipher. It accepts a key length and a function that returns a cipher.AEAD. This allows very easy symmecrypt implementations of any cipher that respects the AEAD interface.

func NewFactoryAEADMutex

func NewFactoryAEADMutex(keyLen int, cipherFactory cipherFactoryFunc) symmecrypt.KeyFactory

func NewKeyAEAD

func NewKeyAEAD(rawkey []byte, keyLen int, factory cipherFactoryFunc) (symmecrypt.Key, error)

func NewKeySequenceAEAD added in v0.5.0

func NewKeySequenceAEAD(rawkey []byte, keyLen int, factory cipherFactoryFunc) (symmecrypt.Key, error)

func NewRandomKeyAEAD

func NewRandomKeyAEAD(keyLen int, factory cipherFactoryFunc) (symmecrypt.Key, error)

NewRandomKeyAEAD needs the desired key length, and an AEAD cipher factory.

func Random

func Random(keyLen int) ([]byte, error)

Random returns a random array of raw bytes of len keyLen.

func RandomSalt added in v0.5.0

func RandomSalt() string

func RawKey

func RawKey(b []byte, keyLen int) ([]byte, error)

RawKey accepts either a raw byte array of len keyLen, or a hex-encoded representation of len keyLen*2. It always returns an array of raw bytes of len keyLen.

Types

type KeyAEAD

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

KeyAEAD is a base implementation of a symmecrypt key that uses AEAD ciphers. It transforms any AEAD cipher factory into a full-fledged symmecrypt key implementation.

func (KeyAEAD) Decrypt

func (b KeyAEAD) Decrypt(text []byte, extra ...[]byte) ([]byte, error)

Decrypt arbitrary data. Extra data can be passed for MAC.

func (KeyAEAD) DecryptMarshal

func (b KeyAEAD) DecryptMarshal(s string, target interface{}, extra ...[]byte) error

DecryptMarshal decrypts the marshaled representation of an arbitrary object. Extra data can be passed for MAC.

func (*KeyAEAD) Encrypt

func (b *KeyAEAD) Encrypt(text []byte, extra ...[]byte) ([]byte, error)

Encrypt arbitrary data. Extra data can be passed for MAC.

func (KeyAEAD) EncryptMarshal

func (b KeyAEAD) EncryptMarshal(i interface{}, extra ...[]byte) (string, error)

EncryptMarshal encrypts the marshaled representation of an arbitrary object. Extra data can be passed for MAC.

func (KeyAEAD) String

func (b KeyAEAD) String() (string, error)

String returns a hex encoded representation of the key

func (KeyAEAD) Wait

func (b KeyAEAD) Wait()

Wait is a noop for regular implementations: the key is always ready

type KeyMutex

type KeyMutex struct {
	Key symmecrypt.Key
	// contains filtered or unexported fields
}

KeyMutex wraps a symmecrypt Key with a mutex to protect unsafe concurrent implementations

func (*KeyMutex) Decrypt

func (k *KeyMutex) Decrypt(text []byte, extra ...[]byte) ([]byte, error)

func (*KeyMutex) DecryptMarshal

func (k *KeyMutex) DecryptMarshal(s string, target interface{}, extra ...[]byte) error

func (*KeyMutex) Encrypt

func (k *KeyMutex) Encrypt(text []byte, extra ...[]byte) ([]byte, error)

func (*KeyMutex) EncryptMarshal

func (k *KeyMutex) EncryptMarshal(i interface{}, extra ...[]byte) (string, error)

func (*KeyMutex) String

func (k *KeyMutex) String() (string, error)

func (*KeyMutex) Wait

func (k *KeyMutex) Wait()

Jump to

Keyboard shortcuts

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