encrypt

package
v0.1.25 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package encrypt provides the encrypter for the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(ciphertextBase64 string, key []byte, encryptMethod Type) ([]byte, error)

Decrypt decrypts ciphertext using the specified encryption method with the given key.

func Encrypt

func Encrypt(plaintext, key []byte, encryptMethod Type) (string, error)

Encrypt encrypts plaintext using the specified encryption method with the given key and IV.

func PKCS7Padding

func PKCS7Padding(data []byte, blockSize int) []byte

PKCS7Padding adds padding to the plaintext to make it a multiple of the block size.

func PKCS7Unpadding

func PKCS7Unpadding(data []byte) []byte

PKCS7Unpadding removes padding from the plaintext.

Types

type Container

type Container map[string]Encrypter

Container is the container for the encrypter.

func NewContainerFromConfig

func NewContainerFromConfig(str store.Store, conf config.ValidEncryptConfig) (Container, error)

NewContainerFromConfig creates a new encrypter container.

type DynamicEncrypter

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

DynamicEncrypter is the dynamic encrypter.

func NewDynamicEncrypter

func NewDynamicEncrypter(
	str store.Store,
	storeBucketID,
	storeKey string,
	method Type,
) (*DynamicEncrypter, error)

NewDynamicEncrypter creates a new dynamic encrypter.

func (*DynamicEncrypter) Decrypt

func (e *DynamicEncrypter) Decrypt(ciphertextBase64 string) ([]byte, error)

Decrypt decrypts the ciphertext using the dynamic encrypter.

func (*DynamicEncrypter) Encrypt

func (e *DynamicEncrypter) Encrypt(plaintext []byte) (string, error)

Encrypt encrypts the plaintext using the dynamic encrypter.

type Encrypter

type Encrypter interface {
	Encrypt(plaintext []byte) (string, error)
	Decrypt(ciphertextBase64 string) ([]byte, error)
}

Encrypter is the interface for the encrypter.

type StaticEncrypter

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

StaticEncrypter is the static encrypter.

func NewStaticEncrypter

func NewStaticEncrypter(key []byte, method Type) (*StaticEncrypter, error)

NewStaticEncrypter creates a new static encrypter.

func (*StaticEncrypter) Decrypt

func (e *StaticEncrypter) Decrypt(ciphertextBase64 string) ([]byte, error)

Decrypt decrypts the ciphertext using the static encrypter.

func (*StaticEncrypter) Encrypt

func (e *StaticEncrypter) Encrypt(plaintext []byte) (string, error)

Encrypt encrypts the plaintext using the static encrypter.

type Type

type Type string

Type is the type of the encrypt.

const (
	// EncryptTypeCBC is the type of the cbc.
	EncryptTypeCBC Type = "CBC"
	// EncryptTypeCFB is the type of the cfb.
	EncryptTypeCFB Type = "CFB"
	// EncryptTypeCTR is the type of the ctr.
	EncryptTypeCTR Type = "CTR"
)

Jump to

Keyboard shortcuts

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