aes

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPassword = errors.New("invalid password")

Functions

func DecryptFile

func DecryptFile(filename string, password string, appendPrefix bool, extLen int) error

DecryptFile decrypts an encrypted file using the provided password. The decrypted content is saved to a new file with a "dec_" prefix added to the original filename.

Parameters:

  • filename: The path to the encrypted file.
  • password: The password used for decryption.
  • appendPrefix: A boolean to determine if a prefix should be added to the decrypted file.
  • extLen: Extension character length of the encrypted file.

Returns:

  • error: An error if the decryption process fails, otherwise nil.

The function performs the following steps:

  1. Opens the encrypted file for reading.
  2. Creates a new file for writing the decrypted content.
  3. Reads the saved password hash, IV, and salt from the encrypted file.
  4. Validates the provided password against the saved password hash.
  5. Generates a decryption key using PBKDF2 with the provided password and salt.
  6. Creates a new AES cipher block and a CTR stream for decryption.
  7. Reads the encrypted content in chunks, decrypts it, and writes the decrypted content to the new file.

If the password is invalid, the function deletes the partially created destination file and returns an error.

func EncryptFile

func EncryptFile(filename string, pass *string, outputExt string) (string, error)

EncryptFile encrypts the contents of the specified file using AES encryption in CTR mode. It generates a random salt and password, derives an encryption key using PBKDF2, and writes the IV and salt to the beginning of the output file. The encrypted data is written to a new file with the same name as the original file but with an additional extension.

Parameters:

  • filename: The path to the file to be encrypted.
  • pass: A pointer use for the password used for encryption. If nil, a random password will be generated.
  • outputExt: The extension to append to the encrypted file.

Returns:

  • string: The password used for encryption.
  • error: An error if any step of the encryption process fails, otherwise nil.

Types

This section is empty.

Jump to

Keyboard shortcuts

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