alanacrypt

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 19 Imported by: 0

README

alana-crypt module

Golang module used in Alana Research encryption related projects.

Example

// Example folder encrypt
al, _ := alanacrypt.NewFolderEncryption("/path/to/encrypt", "myExtension")
al.Encrypt()

//Example folder decrypt
al, _ := alanacrypt.NewFolderEncryption("/path/encrypted", "encryptedExtension", alanacrypt.WithEncryptionKey(keyDec))
al.DecryptFiles()

//It uses the functional options patter so you can modfify file read buffer size and add your own logger:
alanacrypt.WithBufferSize(8192)
alanacrypt.WithLogger(alanacrypt.LoggerFunc(func(args ...interface{}) {
  //your custom logger
	tlog.Warn(args...)
})
//Asymmetric encryption and decryption example
asym, _ := alanacrypt.NewAssymetricEncryption(
	alanacrypt.WithLoggerForAsymmetricEnc(alanacrypt.LoggerFunc(func(args ...interface{}) {
		tlog.Info(args...)
})))

keyDec, err := asym.RetrieveAndDecryptEncKeyFromFile("./keySaved.txt", private_key_file)
keyEnc, err := asym.RSAEncrypt(key, RSA4096PubKeyString)
pathSaved, err := asym.SaveAsHEXToFile(keyEnc, "./", "keySaved", "txt")

TODO:

Documentation

Index

Constants

View Source
const (
	DEFAULT_BUFFER_SIZE = 4096
)

Variables

This section is empty.

Functions

func ConvertByteArrayToHex

func ConvertByteArrayToHex(arr []byte) string

func ConvertByteArrayToString

func ConvertByteArrayToString(arr []byte) string

func ConvertHexToByteArray

func ConvertHexToByteArray(hexa string) ([]byte, error)

func CreateAES256Key

func CreateAES256Key() []byte

func FileDecryption

func FileDecryption(filePath string, aesKey []byte, bufferSize int, fileExtension string) error

func FileEncryption

func FileEncryption(filePath string, key []byte, bufferSize int, fileExtension string) error

func GetFiles

func GetFiles(rootPath string) []string

Types

type AsymmetricEncOptions

type AsymmetricEncOptions func(*AsymmetricEncryption)

func WithLoggerForAsymmetricEnc

func WithLoggerForAsymmetricEnc(logger Logger) AsymmetricEncOptions

type AsymmetricEncryption

type AsymmetricEncryption struct {
	Logger Logger
}

func NewAssymetricEncryption

func NewAssymetricEncryption(args ...AsymmetricEncOptions) (*AsymmetricEncryption, error)

func (*AsymmetricEncryption) RSAEncrypt

func (asymEnc *AsymmetricEncryption) RSAEncrypt(keyToEncrypt []byte, pubKey string) ([]byte, error)

func (*AsymmetricEncryption) RetrieveAndDecryptEncKeyFromFile

func (asymEnc *AsymmetricEncryption) RetrieveAndDecryptEncKeyFromFile(filePath string, rsa_private_key_path string) ([]byte, error)

func (*AsymmetricEncryption) SaveAsHEXToFile

func (asymEnc *AsymmetricEncryption) SaveAsHEXToFile(key []byte, path string, filename string, fileExtension string) (string, error)

type EncOptions

type EncOptions func(*FolderEncryption)

func WithBufferSize

func WithBufferSize(size int) EncOptions

func WithEncryptionKey

func WithEncryptionKey(key []byte) EncOptions

func WithLogger

func WithLogger(logger Logger) EncOptions

type FolderEncryption

type FolderEncryption struct {
	Folder        string
	FileExtension string
	BufferSize    int
	SymmetricKey  []byte
	Logger        Logger
}

func NewFolderDecryption

func NewFolderDecryption(encryptedPath string, opts ...EncOptions) (*FolderEncryption, error)

func NewFolderEncryption

func NewFolderEncryption(pathToEncrypt string, fileExtension string, opts ...EncOptions) (*FolderEncryption, error)

func (*FolderEncryption) DecryptFiles

func (opts *FolderEncryption) DecryptFiles() (int64, error)

func (*FolderEncryption) Encrypt

func (opts *FolderEncryption) Encrypt() (int64, error)

type Logger

type Logger interface {
	Log(...interface{})
}

Should be used to provide custom logging writers for the SDK to use.

type LoggerFunc

type LoggerFunc func(...interface{})

Wrapper for client to satisfy Logger interface

Ex: alanacrypt.LoggerFunc(func(args ...interface{}) {
        fmt.Fprintln(os.Stdout, args...)
    }

func (LoggerFunc) Log

func (f LoggerFunc) Log(args ...interface{})

Log calls the wrapped function with the arguments provided

Jump to

Keyboard shortcuts

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