Class CryptFile() Professional

Class function of the CryptFile() class

Description

The CryptFile class provides encryption and decryption of files, such as text files. To encrypt a file, a crypt-provider object and a key-object is required. The crypt-provider determines the algorithm used for encryption, and the key-object provides the cipher key to be used by the crypt-provider.

SecureKey():destroy() can be called right after encrypting or decrypting a file. The key value is required during that operation.

Class methods
:new()
Creates an instance of the CryptFile class.
Instance variables
:bufferSize
Determines the buffer size for file encryption.
Methods
:encrypt()
Encrypts a file.
:decrypt()
Decrypts a file.
Examples
Crypting a file
// In this example, a plain text file is encrypted using 
// a supplied key 

#include "crypt.ch" 

PROCEDURE MAIN(cFile, cKey) 
   LOCAL oAes 
   LOCAL oFile 
   LOCAL oKey 

   // setup key object 
   oKey := SecureKey():new() 
   oKey:setStrKey(cKey) 

   // use AES for encryption 
   oAes := AesCrypt():new(oKey) 
   oFile := CryptFile():new(oAes, oKey) 

   // now encrypt file in two buffers 
   oFile:bufferSize := FSize(cFile)/2 
   oFile:encrypt(cFile, cFile+".enc") 

   // destroy key 
   oKey:destroy() 
   ? cFile+".enc created" 
RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.