EncryptFile Method  
 

Encrypt the contents of the specified file.

Syntax

object.EncryptFile( InputFile, OutputFile [, Password] )

Parameters

InputFile
A string value that specifies the name of the file to be encrypted. 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 the console, is specified as the file name.
OutputFile
A string value that specifies the name of the file that will contain the encrypted 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 the console, is specified as the file name.
Password
An optional parameter that specifies the password that was used to encrypt the file contents. If this parameter is omitted, the value of the Password property will be used.

Return Value

This method returns a value of zero if the file was successfully encrypted. A non-zero return value specifies an error code which indicates the reason for the failure.

Remarks

The EncryptFile method will encrypt the contents of a file using a 256-bit AES (Advanced Encryption Standard) algorithm and stores the encrypted data in the specified output file. The password (or passphrase) provided by the caller is used to generate a SHA-256 hash value which is used as part of the encryption process. The identical password is required to decrypt the data using the DecryptFile method.

Although it is not required for your application to use a password to encrypt the data, it is recommended. If no password is specified, any other application that uses this control will be able to decrypt the data. Passwords are case-sensitive and must match exactly, including the use of any spaces.

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

If you wish to encrypt or decrypt string values, use the DecryptedText and EncryptedText properties.

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

DecryptedText Property, EncryptedText Property, Password Property, DecryptData, EncryptData, EncryptFile Method