crypto

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package crypto provides security tools

Index

Constants

View Source
const (
	// CKeySize is the cipher key size - AES-256
	CKeySize = 32
	// MKeySize is the HMAC key size - HMAC-SHA-256
	MKeySize = 32
	// KeySize is the encryption key size
	KeySize = CKeySize + MKeySize
	// AESNonceSize is an AES nonce size
	AESNonceSize = aes.BlockSize
	// GCMNonceSize is a GCM nonce size
	GCMNonceSize = 12
	// SenderSize is the size allocated to add the sender ID
	SenderSize = 4
	// MACSize MAC size
	MACSize = 32
)

Variables

View Source
var (
	// ErrEncrypt occurs when the encryption process fails. The reason of failure
	// is concealed for security reason
	ErrEncrypt = errors.New("sec: encryption failed")
	// ErrDecrypt occurs when the decryption process fails.
	ErrDecrypt = errors.New("sec: decryption failed")
)

Functions

func Decrypt

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

Decrypt recovers a message secured using AES-GCM.

func Encrypt

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

Encrypt secures a message using AES-GCM.

Types

type Rotor

type Rotor struct {
	NonceSize int
	// contains filtered or unexported fields
}

Rotor is a encryption/decryption tool that supports key rotation

Note: Data encrypted with sec.Encrypt cannot be decrypted with Rotor

func NewRotor

func NewRotor(keys map[uint32][]byte, defaultSender uint32) *Rotor

NewRotor creates a new Rotor with the given keys. The defaultSender will be used as the default sender ID during the encryption process

func (*Rotor) Decrypt

func (r *Rotor) Decrypt(message []byte) ([]byte, error)

Decrypt takes an incoming message and uses the sender ID to retrieve the appropriate key. It then attempts to recover the message using that key.

func (*Rotor) Encrypt

func (r *Rotor) Encrypt(message []byte) ([]byte, error)

Encrypt secures a message and prepends the default 4-byte sender ID to the message.

func (*Rotor) EncryptWithSender

func (r *Rotor) EncryptWithSender(message []byte, sender uint32) ([]byte, error)

EncryptWithSender secures a message and prepends the given 4-byte sender ID to the message.

Jump to

Keyboard shortcuts

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