crypto

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(encrypted string, passphrase string) ([]byte, error)

Decrypt decrypts the given encrypted string using the provided passphrase. It returns the decrypted data as a byte slice. If an error occurs during decryption, it returns nil and the corresponding error.

func Encrypt

func Encrypt(data []byte, passphrase string) (string, error)

Encrypt encrypts the given data using the provided passphrase. It returns the encrypted data as a hexadecimal string and any error encountered.

func GenerateRandomKey added in v0.3.1

func GenerateRandomKey(length int) []byte

GenerateRandomKey generates a random key of the specified length. It uses the crypto/rand package to generate random bytes and returns the key as a byte slice. If an error occurs during the generation process, it logs the error and returns nil.

func HashByte

func HashByte(data []byte) [32]byte

HashByte calculates the SHA3-256 hash of the given byte slice. It returns a fixed-size array of 32 bytes representing the hash.

func HashString

func HashString(data string) [32]byte

HashString calculates the SHA3-256 hash of the input string. It takes a string as input and returns a fixed-size array of 32 bytes.

func HashStringToString added in v0.2.5

func HashStringToString(data string) string

HashStringToString takes a string as input and returns its SHA3-256 hash as a hexadecimal string.

Types

type Crypto

type Crypto interface {
	// HashString calculates the hash of a string and returns a fixed-size byte array.
	HashString(data string) [32]byte

	// HashByte calculates the hash of a byte slice and returns a fixed-size byte array.
	HashByte(data []byte) [32]byte

	// Encrypt encrypts the given byte slice using the provided passphrase and returns the encrypted data as a string.
	Encrypt(data []byte, passphrase string) (string, error)

	// Decrypt decrypts the given encrypted string using the provided passphrase and returns the decrypted data as a byte slice.
	Decrypt(encrypted string, passphrase string) ([]byte, error)
}

Crypto is an interface that defines cryptographic operations.

Jump to

Keyboard shortcuts

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