Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
|
Blowfish Encryption in Visual FoxPro
Demonstrates string-to-string blowfish encryption in Visual FoxPro ***********************************************************
*** Blowfish String Encryption in Visual Foxpro (VFP)
***********************************************************
LOCAL blowfish, keyBytes, cipherText, clearText
blowfish = CreateObject('Chilkat.Crypt2')
blowfish.UnlockComponent('Anything for 30-day trial')
* Set the encryption algorithm to blowfish.
* Use "blowfish2" to enable cipher-block chaining (CBC) to be used.
blowfish.CryptAlgorithm = 'blowfish2'
* Set the cipher mode to cbc (this is the default). The other cipher mode is 'ecb'.
blowfish.CipherMode = 'cbc'
* The key length can be anything from 64 bits to 448 bits
blowfish.KeyLength = 256
* Padding Schemes:
* 0((RFC2630) Each padding byte is the pad count (16 extra added if size is already a multiple of 16)
* 1(Random bytes except the last is the pad count (16 extra added if size is already multiple of 16)
* 2(Pad with random data. (If already a multiple of 16, no padding is added).
* 3(Pad with NULLs. (If already a multiple of 16, no padding is added).
* 4(Pad with SPACE chars(0x20). (If already a multiple of 16, no padding is added).
blowfish.PaddingScheme = 4
* Set the 8-byte initialization vector via a hex encoded string.
* Blowfish is a 64-bit block cipher, so the IV is always 64 bits.
blowfish.SetEncodedIV('0001020304050607', 'hex')
* Set our secret key. To do this, we hash a password string to a binary secret key
* having the correct bit length (equal to the key length).
keyBytes = blowfish.GenerateSecretKey('secret_password')
blowfish.SecretKey = keyBytes
* Encrypt a string, returning the encrypted data as a hex encoded string.
blowfish.EncodingMode = 'hex'
cipherText = blowfish.EncryptStringENC('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
* The blowfish algorithm pads to a 16-byte multiple. In this example, the 26-byte
* input string is padded to 32 bytes with SPACE characters and encrypted.
* The result is a 64-byte hex string (2 characters per binary byte)
=MESSAGEBOX(cipherText)
* Decrypting is easy...
clearText = blowfish.DecryptStringENC(cipherText)
* The decrypted string will contain the padding, so it needs to be trimmed.
=MESSAGEBOX(TRIM(clearText))
RELEASE blowfish
RETURN .T.
|
© 2000-2010 Chilkat Software, Inc. All Rights Reserved.
Mail Component · .NET Email Component · ASP Mail Component · XML Parser