transcrypt

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: May 27, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package transcrypt provides functionality to encrypt arbitrary data into a hex encoded string for safe on-disk storage, and decrypt said string.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateHexKey

func CreateHexKey(bitSize int) (string, error)

CreateHexKey generates a random key which can be used for encryption. It generates a RSA Private Key with the supplied bitSize, and converts it to a hex-encoded PEM Block.

func CreateSalt

func CreateSalt() ([]byte, error)

CreateSalt creates a random 12-byte salt for use with the encrypt/decrypt functionality.

func Decrypt

func Decrypt(key string, data string) (any, error)

Decrypt decrypts a supplied hex-encoded data string using the supplied secret key. It will return an error if either the key or the data is empty. If the hex-encoded string data cannot be converted into proper encrypted data, decryption will also fail with an error.

func Encrypt

func Encrypt(key string, salt []byte, cipherSuite CipherSuite, d any) (string, error)

Encrypt encrypts the supplied data using the supplied secret key and cipher suite. It will return an error if either the key is empty or the data is nil. Additionally, if the necessary cryptographic configuration cannot be created using the supplied cipherSuite, it will return an error. If a salt is provided, it must be at least 12 bytes. If salt is nil, the function will automatically create one on-the-fly.

Types

type CipherSuite

type CipherSuite byte

CipherSuite defines which cipher suites can be used for transcryption of data. It is based on the types available in github.com/minio/sio .

const (
	AES_256_GCM CipherSuite = iota
	CHACHA20_POLY1305
)

func GetCipherSuite

func GetCipherSuite(s string) CipherSuite

GetCipherSuite converts a string into its respective CipherSuite. It returns CHACHA20_POLY1305 by default if the string cannot be converted.

Jump to

Keyboard shortcuts

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