crypto

package
v0.0.0-...-493bf59 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2021 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// KeySize is the size of the encryption key in bytes
	KeySize = 32
	// IVSize is the size of the IV in bytes
	IVSize = 12
	// LegacyIVSize is the size of the IV in bytes for the legacy encryption scheme
	LegacyIVSize = 16
	// AADSize is the size in bytes of the Additional Authenticated Data for the
	// GCM encryption
	AADSize = 16
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ICrypto

type ICrypto interface {
	DecryptFile(encryptedFilePath, key, iv, outputFilePath string) error
	EncryptFile(plainFilePath string, key, iv []byte) (string, error)
	NewEncryptReader(reader io.Reader, key, iv []byte) (*gcm.EncryptReader, error)
	NewDecryptWriteCloser(writeCloser io.WriteCloser, key, iv string) (*gcm.DecryptWriteCloser, error)
	Hex(src []byte, maxLen int) []byte
	Unhex(src []byte, maxLen int) []byte
	Base64Encode(src []byte, maxLen int) []byte
	Base64Decode(src []byte, maxLen int) []byte
}

ICrypto

func New

func New() ICrypto

New creates a new instance of ICrypto

type SCrypto

type SCrypto struct{}

SCrypto is an implementor of ICrypto

func (*SCrypto) Base64Decode

func (c *SCrypto) Base64Decode(src []byte, maxLen int) []byte

Base64Decode bytes

func (*SCrypto) Base64Encode

func (c *SCrypto) Base64Encode(src []byte, maxLen int) []byte

Base64Encode bytes

func (*SCrypto) DecryptFile

func (c *SCrypto) DecryptFile(encryptedFilePath, key, iv, outputFilePath string) error

DecryptFile takes in an ecrypted file and decrypts it to the given output path based on the Key and IV. The Key and IV should be the hex and base64 encoded version

func (*SCrypto) EncryptFile

func (c *SCrypto) EncryptFile(plainFilePath string, key, iv []byte) (string, error)

EncryptFile takes in an open plaintext file and encrypts it to a temporary location based on the key and IV. It is up to the caller to ensure the encrypted file is deleted after it's used. The passed in key and iv should *NOT* be base64 encoded or hex encoded.

func (*SCrypto) Hex

func (c *SCrypto) Hex(src []byte, maxLen int) []byte

Hex encode bytes

func (*SCrypto) NewDecryptWriteCloser

func (c *SCrypto) NewDecryptWriteCloser(writeCloser io.WriteCloser, key, iv string) (*gcm.DecryptWriteCloser, error)

NewDecryptWriteCloser takes a io.WriteCloser and wraps it in a type that will decrypt Writes to the io.WriteCloser as they are written. The passed in key and iv should *NOT* be base64 encoded or hex encoded.

func (*SCrypto) NewEncryptReader

func (c *SCrypto) NewEncryptReader(reader io.Reader, key, iv []byte) (*gcm.EncryptReader, error)

NewEncryptReader takes in a Reader and wraps it in a type that will encrypt the Reader as its read. The passed in key and iv should *NOT* be base64 encoded or hex encoded.

func (*SCrypto) Unhex

func (c *SCrypto) Unhex(src []byte, maxLen int) []byte

Unhex bytes

Jump to

Keyboard shortcuts

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