SocketTools .NET Edition

FileEncoder.DecryptFile Method (String, String)

Decrypts the contents of a file using AES-256 encryption.

[Visual Basic]
Overloads Public Function DecryptFile( _
   ByVal inputFile As String, _
   ByVal outputFile As String _
) As Boolean
[C#]
public bool DecryptFile(
   string inputFile,
   string outputFile
);

Parameters

inputFile
A string which specifies the name of the file to be decrypted. The file must exist, and it must be a regular file that can be opened for reading by the current process. An error will be returned if a character device, such as CON: is specified as the file name.
outputFile
The name of the file that is to contain the decrypted file data. If the file exists, it must be a regular file that can be opened for writing by the current process and will be overwritten. If the file does not exist, it will be created. An error will be returned if a character device, such as CON: is specified as the file name.

Return Value

A boolean value which specifies if the method was successful or not. A return value of True indicates that the method call completed successfully. A return value of False indicates that the method failed and the application should check the value of the LastError property.

Remarks

This method will decrypt the contents of a file using a 256-bit AES (Advanced Encryption Standard) algorithm and stores the decrypted data in the specified output file. The value of the Password property is used to generate a SHA-256 hash value which is used as part of the decryption process. The password must be identical to the value used to encrypt the data using the EncryptFile method.

Due to how the SHA-256 hash is generated, this method cannot be used to decrypt files that were encrypted using another third-party library. It can only be used to decrypt data that was previously encrypted using the EncryptFile method.

A temporary file is created during the decryption process and the output file is created or overwritten only if the input file could be successfully encrypted. If the decryption fails, no output file will be created.

If you wish to decrypt the contents of a memory buffer or string, use the DecryptData method.

This method uses the Microsoft CryptoAPI and the RSA AES cryptographic provider. This provider may not be available in some languages, countries or regions. The availability of this provider may also be constrained by cryptography export restrictions imposed by the United States or other countries. If the required cryptographic provider is not available, the method will fail.

See Also

FileEncoder Class | SocketTools Namespace | FileEncoder.DecryptFile Overload List | DecryptData | EncryptData | EncryptFile