Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decrypt ¶
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 ¶
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
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 ¶
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 ¶
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
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.