crypto

package
v0.0.0-...-b7da0db Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptValue

func DecryptValue(value string, providers map[string]map[string]EncryptionProvider) ([]byte, error)

DecryptValue decrypts a formatted encrypted value

func EncryptValue

func EncryptValue(provider EncryptionProvider, value []byte) (string, error)

EncryptValue encrypts a value and returns a formatted string

func GenerateSecretKey

func GenerateSecretKey(length int) ([]byte, error)

GenerateSecretKey generates a random secret key of the specified length

Types

type EncryptionProvider

type EncryptionProvider interface {
	Encrypt(plaintext []byte) ([]byte, error)
	Decrypt(ciphertext []byte) ([]byte, error)
	GetProviderType() string
	GetKeyID() string
}

EncryptionProvider represents an interface for encrypting and decrypting data

type KMSEncryptionProvider

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

KMSEncryptionProvider implements encryption using AWS KMS

func NewKMSEncryptionProvider

func NewKMSEncryptionProvider(keyID string, region string) (*KMSEncryptionProvider, error)

NewKMSEncryptionProvider creates a new AWS KMS encryption provider

func (*KMSEncryptionProvider) Decrypt

func (p *KMSEncryptionProvider) Decrypt(ciphertext []byte) ([]byte, error)

Decrypt decrypts ciphertext data using AWS KMS

func (*KMSEncryptionProvider) Encrypt

func (p *KMSEncryptionProvider) Encrypt(plaintext []byte) ([]byte, error)

Encrypt encrypts plaintext data using AWS KMS

func (*KMSEncryptionProvider) GetKeyID

func (p *KMSEncryptionProvider) GetKeyID() string

GetKeyID returns the key ID used by this provider

func (*KMSEncryptionProvider) GetProviderType

func (p *KMSEncryptionProvider) GetProviderType() string

GetProviderType returns the type of this provider

type LocalEncryptionProvider

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

LocalEncryptionProvider implements encryption using local keys

func NewLocalEncryptionProvider

func NewLocalEncryptionProvider(keyID string, key []byte) (*LocalEncryptionProvider, error)

NewLocalEncryptionProvider creates a new local encryption provider

func (*LocalEncryptionProvider) Decrypt

func (p *LocalEncryptionProvider) Decrypt(ciphertext []byte) ([]byte, error)

Decrypt decrypts ciphertext data

func (*LocalEncryptionProvider) Encrypt

func (p *LocalEncryptionProvider) Encrypt(plaintext []byte) ([]byte, error)

Encrypt encrypts plaintext data

func (*LocalEncryptionProvider) GetKeyID

func (p *LocalEncryptionProvider) GetKeyID() string

GetKeyID returns the key ID used by this provider

func (*LocalEncryptionProvider) GetProviderType

func (p *LocalEncryptionProvider) GetProviderType() string

GetProviderType returns the type of this provider

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳