crypto

package
v0.24.5 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptBytes

func DecryptBytes(data []byte, rootKeyTriplet []string) ([]byte, error)

DecryptBytes decrypts a byte slice using the Age encryption algorithm. It is a wrapper function that retrieves the private key from a root key triplet and t hen calls a specific decryption function from the crypto package to perform the decryption.

Parameters: - data ([]byte): The encrypted data as a byte slice that needs to be decrypted.

Returns:

  • ([]byte, error): The function returns two values. The first is a byte slice containing the decrypted data. The second is an error object, which will be non-nil if any errors occurred during the decryption process.

func DecryptBytesAes

func DecryptBytesAes(data []byte, rootKeyTriplet []string) ([]byte, error)

DecryptBytesAes decrypts a byte slice using the AES encryption algorithm. Similar to DecryptBytes, this function retrieves the AES key from a root key triplet and utilizes a specific function from the crypto package to carry out the decryption.

Parameters:

  • data ([]byte): The encrypted data in the form of a byte slice that is to be decrypted.

Returns:

  • ([]byte, error): This function also returns a byte slice containing the decrypted data and an error object. The error will be non-nil if the decryption process encounters any issues.

func DecryptDataFromDisk

func DecryptDataFromDisk(key string, rootKeyTriplet []string) ([]byte, error)

DecryptDataFromDisk takes a key as input and attempts to decrypt the data associated with that key from the disk. The key is used to locate the data file, which is expected to have a ".age" extension and to be stored in a directory specified by the environment's data path for safe storage.

Parameters:

  • key (string): A string representing the unique identifier for the data to be decrypted. The actual data file is expected to be named using this key with a ".age" extension.

Returns:

  • ([]byte, error): This function returns two values. The first value is a byte slice containing the decrypted data if the process is successful. The second value is an error object that will be non-nil if any step of the decryption process fails. Possible errors include the absence of the target data file on disk and failures related to reading the file or the decryption process itself.

func EncryptToWriterAes

func EncryptToWriterAes(out io.Writer, data string, rootKeyTriplet []string) error

EncryptToWriterAes encrypts the given data string using the AES encryption standard and writes the encrypted data to the specified io.Writer. This function emphasizes secure encryption practices, including the management of the Initialization Vector (IV) and the AES key.

Parameters:

  • out (io.Writer): The output writer where the encrypted data will be written. This writer can represent various types of data sinks, such as files, network connections, or in-memory buffers.
  • data (string): The plaintext data to be encrypted. This data is converted to a byte slice and then encrypted using AES.

Returns:

  • error: An error is returned if any step of the encryption or writing process encounters an issue. This includes errors related to call frequency, key management, encryption initialization, and data writing.

func EncryptToWriterAge

func EncryptToWriterAge(out io.Writer, data string, rootKeyTriplet []string) error

EncryptToWriterAge encrypts the provided data using a public key and writes the encrypted data to the specified io.Writer. The encryption is performed using the age encryption protocol, which is designed for simple, secure, and modern encryption.

Parameters:

  • out (io.Writer): The writer interface where the encrypted data will be written. This could be a file, a network connection, or any other type that implements the io.Writer interface.
  • data (string): The plaintext data that needs to be encrypted. This function converts the string to a byte slice and encrypts it.

Returns:

  • error: If any step in the encryption or writing process fails, an error is returned. Possible errors include issues with the public key (such as being empty or unparseable) and failures related to the encryption process or writing to the writer interface.

Types

This section is empty.

Jump to

Keyboard shortcuts

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