Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
File Encryption / DecryptionFile-to-file encryption in Visual FoxPro using AES, Blowfish, RC2, ARC4, or 3DES.
LOCAL loCrypt LOCAL lnSuccess LOCAL lcKey LOCAL lcIv loCrypt = CreateObject('Chilkat.Crypt2') lnSuccess = loCrypt.UnlockComponent("Anything for 30-day trial") IF (lnSuccess <> 1) THEN =MESSAGEBOX("Crypt component unlock failed") QUIT ENDIF loCrypt.CryptAlgorithm = "aes" loCrypt.CipherMode = "cbc" loCrypt.KeyLength = 128 * 16 bytes of key for 128-bit encryption. lcKey = "1234567890123456" * The IV is equal to the block size of the encryption algorithm. lcIv = "1234567890123456" * Set the key. loCrypt.SetEncodedKey(lcKey,"ascii") * Set the IV loCrypt.SetEncodedIV(lcIv,"ascii") * AES Encrypt the file (the file may be any size because it will * stream the file in/out. lnSuccess = loCrypt.CkEncryptFile("hamlet.xml","aesEncrypted.dat") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCrypt.LastErrorText) QUIT ENDIF * AES Decrypt the file (the file may be any size because it will * stream the file in/out. lnSuccess = loCrypt.CkDecryptFile("aesEncrypted.dat","hamlet_aes.xml") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCrypt.LastErrorText) QUIT ENDIF =MESSAGEBOX("AES File Encryption Success.") * Now do 3DES file encryption: * To use Triple-DES, set the algorithm = "des", * and the key length = 168. * To use DES, set the key length = 56 bits. loCrypt.CryptAlgorithm = "des" loCrypt.CipherMode = "cbc" loCrypt.KeyLength = 168 * 3DES Encrypt the file lnSuccess = loCrypt.CkEncryptFile("hamlet.xml","tripleDesEncrypted.dat") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCrypt.LastErrorText) QUIT ENDIF * 3DES Decrypt the file lnSuccess = loCrypt.CkDecryptFile("tripleDesEncrypted.dat","hamlet_3des.xml") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCrypt.LastErrorText) QUIT ENDIF =MESSAGEBOX("3DES File Encryption Success.") * Do Blowfish file encryption: * To use Blowfish, set the algorithm = "blowfish2". * The original Chilkat "blowfish" implementation outputs * 4321 swapped bytes. "blowfish2" output is in the correct * byte order. loCrypt.CryptAlgorithm = "blowfish2" loCrypt.CipherMode = "cbc" loCrypt.KeyLength = 128 * Blowfish Encrypt the file lnSuccess = loCrypt.CkEncryptFile("hamlet.xml","blowfishEncrypted.dat") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCrypt.LastErrorText) QUIT ENDIF * Blowfish Decrypt the file lnSuccess = loCrypt.CkDecryptFile("blowfishEncrypted.dat","hamlet_blowfish.xml") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCrypt.LastErrorText) QUIT ENDIF =MESSAGEBOX("Blowfish File Encryption Success.") * Do RC2 file encryption: * To use RC2, set the algorithm = "rc2". * Also, set the Rc2EffectiveKeyLength property. loCrypt.CryptAlgorithm = "rc2" loCrypt.CipherMode = "cbc" * Key length and effective key length should range * from 8 to 1024 bits. loCrypt.KeyLength = 128 loCrypt.Rc2EffectiveKeyLength = 128 * RC2 Encrypt the file lnSuccess = loCrypt.CkEncryptFile("hamlet.xml","rc2Encrypted.dat") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCrypt.LastErrorText) QUIT ENDIF * RC2 Decrypt the file lnSuccess = loCrypt.CkDecryptFile("rc2Encrypted.dat","hamlet_rc2.xml") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCrypt.LastErrorText) QUIT ENDIF =MESSAGEBOX("RC2 File Encryption Success.") * Do ARC4 file encryption: * To use ARC4, set the algorithm = "arc4". loCrypt.CryptAlgorithm = "arc4" loCrypt.KeyLength = 128 * ARC4 Encrypt the file lnSuccess = loCrypt.CkEncryptFile("hamlet.xml","arc4Encrypted.dat") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCrypt.LastErrorText) QUIT ENDIF * ARC4 Decrypt the file lnSuccess = loCrypt.CkDecryptFile("arc4Encrypted.dat","hamlet_arc4.xml") IF (lnSuccess <> 1) THEN =MESSAGEBOX(loCrypt.LastErrorText) QUIT ENDIF =MESSAGEBOX("ARC4 File Encryption Success.") |
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2007 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser