Professional Documents
Culture Documents
Function ENCRYPT()
Parameters:
cStringtoEncrypt - A plain text string that you want to have encrypted, such as "Hello World!"
cSecretKey - A plain text string that is the Key you want used during encryption, such as
"My_SeCrEt_KeY".
Please note that keys may need to be of a particular length for certain types of encryption. Refer below for
more information.
nEncryptionType - There are currently 5 types of encryption available. The value of this parameter
determines that type of encryption used and how long your Secret Key should be. A single character in
Visual FoxPro is equal to 1 byte or 8 bits. So an encryption algorithm requiring a 128-bit key would need a
Secret Key of 16 characters (16 x 8 = 128).
nEncryptionMode - There are three different modes available for the each of the encryption types listed
above. They include: Electronic Code Book (ECB), Cipher Block Chaining (CBC) and Cipher Feedback
Block (CFB). The nEncryptionMode parameter does not apply to RC4 encryption (nEncryptionType =
1024).
0 = ECB *Default
1 = CBC
2 = CFB
Return Value:
Remarks:
When saving the return value of Encrypt() function to a field in a table, remember that Visual FoxPro will
append blanks to the end of the string in order to fill the character field to its designated length. This can
cause problems when decrypting the data as the spaces will be considered part of the encrypted string. To
work around this, I suggest placing a single CHR(0) at the end of the encrypted string when saving it to the
table. Then when decrypting the data just the portion prior to the CHR(0) can be sent into the Decrypt()
function. This does not apply when using RC4 encryption (nEncryptionType = 1024).
Function DECRYPT()
Parameters:
cEncryptedString - A string that has been encrypted using the Encrypt() function.
cSecretKey - A plain text string that is the same Key that you used when you encrypted the data using the
Encrypt function, such as "My_SeCrEt_KeY".
Please note that keys may need to be of a particular length for certain types of decryption. Refer below for
more information.
nDecryptionType - There are currently 5 types of decryption available and they correspond to the same
ones available in Encrypt(). A single character in Visual FoxPro is equal to 1 byte or 8 bits. So an
decryption algorithm requiring a 128-bit key would need a Secret Key of 16 characters (16 x 8 = 128).
nDecryptionMode - There are three different modes available for the each of the encryption types listed
above. They include: Electronic Code Book (ECB), Cipher Block Chaining (CBC) and Cipher Feedback
Block (CFB). The nDecryptionMode parameter does not apply to RC4 decryption (nDecryptionType =
1024).
0 = ECB *Default
1 = CBC
2 = CFB
Return Value:
Character data type - the decrypted form of cEncryptedString followed by a variable number of CHR(0)s.
See Remarks below for further clarification
Remarks:
IMPORTANT: Decryption is done on blocks of memory, so when the decrypt function returns the encrypted
string it will be followed by a variable number of CHR(0)s unless the decrypted string just happens to end
at exactly the same location as the last block decrypted. These extraneous CHR(0)'s can be removed
using a number of Visual FoxPro functions, such as STRTRAN(), CHRTRAN(), or a combination of LEFT()
and AT(). This does not apply when using RC4 decryption (nDecryptionType = 1024).
Function ENCRYPTFILE()
Parameters:
cFiletoEncrypt - A plain text string that is the fullpath to the file you wish to be encrypted, such as
"C:\SensitiveInfo.doc"
cDestinationFile - A plain text string that is the fullpath to an encrypted file you wish to have created on
disk, such as "C:\EncryptedInfo.doc". If this file doesn't exist then it will be created for you.
cSecretKey - A plain text string that is the Key you want used during encryption, such as
"My_SeCrEt_KeY".
Please note that keys may need to be of a particular length for certain types of encryption. Refer below for
more information.
nEncryptionType - There are currently 5 types of encryption available. The value of this parameter
determines that type of encryption used and how long your Secret Key should be. A single character in
Visual FoxPro is equal to 1 byte or 8 bits. So an encryption algorithm requiring a 128-bit key would need a
Secret Key of 16 characters (16 x 8 = 128).
0 = ECB *Default
1 = CBC
2 = CFB
Return Value:
None
Remarks:
Currently the cFiletoEncrypt and cDestinationFile parameters cannot point to the same file. This may be
revised in a future version. But for safety sake, this function requires that the original file be left untouched.
Function DECRYPTFILE()
Parameters:
cEncyptedFile - A plain text string that is the fullpath to the file you wish to be decrypted, such as
"C:\EncryptedInfo.doc"
cDestinationFile - A plain text string that is the fullpath to a decrypted file you wish to have created on disk,
such as "C:\SensitiveInfo.doc". If this file doesn't exist then it will be created for you.
cSecretKey - A plain text string that is the same Key that you used when you encrypted the data using the
Encrypt function, such as "My_SeCrEt_KeY".
Please note that keys may need to be of a particular length for certain types of decryption. Refer below for
more information.
nDecryptionType - There are currently 5 types of decryption available and they correspond to the same
ones available in Encrypt(). A single character in Visual FoxPro is equal to 1 byte or 8 bits. So an
decryption algorithm requiring a 128-bit key would need a Secret Key of 16 characters (16 x 8 = 128).
nDecryptionMode - There are three different modes available for the each of the encryption types listed
above. They include: Electronic Code Book (ECB), Cipher Block Chaining (CBC) and Cipher Feedback
Block (CFB). This does not apply when using RC4 decryption (nDecryptionType = 1024).
0 = ECB *Default
1 = CBC
2 = CFB
Return Value:
None
Remarks:
As with EncryptFile(), the cFiletoEncrypt and cDestinationFile parameters cannot point to the same file.
Function HASH()
Signature: Hash(cStringtoHash[, nHashType])
Parameters:
nHashType - The type of hash function to generate. There are currently 7 different hash functions
supported
Return Value:
Remarks:
The hash is returned as a series of binary characters. However, it is more common to see hashes in a
hexBinary format. This can be accomplished in Visual FoxPro by taking the return of the Hash() function
and sending it in as a parameter to the STRCONV() function. For example:
Function HASHFILE()
Parameters:
cFileName - The fullpath and name of an existing file you wish to generate a message digest for
nHashType - The type of hash function to generate. There are currently 7 different hash functions
supported
Return Value:
Remarks:
The hash is returned as a series of binary characters. However, it is more common to see hashes in a
hexBinary format. This can be accomplished in Visual FoxPro by taking the return of the HashFile()
function and sending it in as a parameter to the STRCONV() function. For example:
Function HASHRECORD()
Signature: HashRecord(cAlias[, nHashType[,lIncludeMemos]])
Parameters:
nHashType - The type of hash function to generate. There are currently 7 different hash functions
supported
lIncludeMemos - Flag determining whether Memo fields should be included when generating the message
digest. .T. = Include Memo Fields, .F. = Exclude Memo Fields
Return Value:
Binary Character Data - the hash for the current record in cAlias.
Remarks:
The hash is returned as a series of binary characters. However, it is more common to see hashes in a
hexBinary format. This can be accomplished in Visual FoxPro by taking the return of the HashRecord()
function and sending it in as a parameter to the STRCONV() function. For example:
Function CRC()
Parameters:
nCRCType - The type of CRC to generate. There are currently 2 different CRC types supported
1 = 16-bit
2 = 32-bit
Return Value:
Remarks:
The CRC that is returned is unsigned, which means that the returned 16-bit CRC needs to be treated as a
4 Byte numeric value and the 32-bit CRC as a 8 byte numeric value in Visual FoxPro. The operation of the
CRC() function presented here is quite similar to Visual FoxPro's Sys(2007) function, however you will find
that creation of 32-bit CRCs is much faster using this function.
Function CRCFILE()
Parameters:
cFileName - The fullpath and name of an existing file you wish to generate a CRC for
nCRCType - The type of CRC to generate. There are currently 2 different CRC types supported
1 = 16-bit
2 = 32-bit
Return Value:
Remarks:
The CRC that is returned is unsigned, which means that the returned 16-bit CRC needs to be treated as a
4 Byte numeric value and the 32-bit CRC as a 8 byte numeric value in Visual FoxPro.
Function CRCRECORD()
Parameters:
nCRCType - The type of CRC to generate. There are currently 2 different CRC types supported
1 = 16-bit
2 = 32-bit
lIncludeMemos - Flag determining whether Memo fields should be included when generating the message
digest. .T. = Include Memo Fields, .F. = Exclude Memo Fields
Return Value:
Remarks:
The CRC that is returned is unsigned, which means that the returned 16-bit CRC needs to be treated as a
4 Byte numeric value and the 32-bit CRC as a 8 byte numeric value in Visual FoxPro. The operation of the
CRC() function presented here is quite similar to Visual FoxPro's Sys(2017) function, however you will find
that this CRC function is faster than Visual FoxPro's Sys(2017). Also, this function allows you to specify a
table alias, which allows CRCs to be created for a record in a table other than the currently selected work
area. On the downside, this function does not allow you to specify a comma delimited list of fields to
exclude like Sys(2017) does.