Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidPassword = errors.New("invalid password")
Functions ¶
func DecryptFile ¶
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:
- Opens the encrypted file for reading.
- Creates a new file for writing the decrypted content.
- Reads the saved password hash, IV, and salt from the encrypted file.
- Validates the provided password against the saved password hash.
- Generates a decryption key using PBKDF2 with the provided password and salt.
- Creates a new AES cipher block and a CTR stream for decryption.
- 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 ¶
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.