Examples for CryptoSys API
VB Encryption Demo | Encryption Scheme using Triple DES in CBC mode | Encryption using a password | htpasswd using SHA-1 | Compression and encryption | MySecret | More information and techniques | VB6/VBA Tests | C/C++ Tests | C# Tests | VB.NET Tests | ASP/VBScript
CryptoSys3.vbp has a set of examples showing
how to encrypt with various algorithms and modes. The source code for this project is in the
file CryptoSysVBDemo.zip provided with the standard installation setup, as well as the
compiled executable CryptoSys3.exe.
The core functions are in CryptoSys.frm.
APITests.VB6.zip
provided with the installation download has a series of tests that call
almost every function in the API and carry out all the examples in the manual.
These projects are included in the standard installation setup and should be found
in the folder
C:\Program Files\CryptoSys\VB6unless you specified another location during the setup process.
TestAPIcsharp.zip which should be in the directory
C:\Program Files\CryptoSysAPI\DotNetunless you specified a different folder during installation.
Here is some simple C# code showing how to encrypt and decrypt a string using Blowfish in ECB mode. (Warning: ECB mode has security weaknesses. We recommend you use CBC mode with a fresh, randomly-generated initialization vector (IV) each time.)
Console.WriteLine("CryptoSys API Version={0}", General.Version());
// ENCRYPTION.
// INPUT: data string, key in hex format
// OUTPUT: ciphertext in hex format
Console.WriteLine("ENCRYPTION:");
string keyHex = "FEDCBA9876543210";
string data = "Some text";
// 1. Convert string to hex format
string dataHex= Cnv.ToHex(data);
// 2. Pad it ready for encryption
string plainHex = Blowfish.Pad(dataHex);
Console.WriteLine("Key ={0}", keyHex);
Console.WriteLine("Data ='{0}'", data);
Console.WriteLine("In Hex ={0}", dataHex);
Console.WriteLine("Input to cipher ={0}", plainHex);
// 3. Encrypt it
string cipherHex = Blowfish.Encrypt(plainHex, keyHex, Mode.ECB, null);
Console.WriteLine("Ciphertext ={0}", cipherHex);
// DECRYPTION.
// INPUT: ciphertext in hex format, key in hex format
// OUTPUT: data string OR "decryption failed" error
Console.WriteLine("DECRYPTION:");
Console.WriteLine("Key ={0}", keyHex);
Console.WriteLine("Ciphertext ={0}", cipherHex);
// 1. Decrypt ciphertext
plainHex = Blowfish.Decrypt(cipherHex, keyHex, Mode.ECB, null);
Console.WriteLine("Output in hex ={0}", plainHex);
// 2. Unpad it
dataHex = Blowfish.Unpad(plainHex);
Console.WriteLine("After unpadding ={0}", dataHex);
// 3. Check for error (see CryptoSysAPI.chm help)
if (dataHex.Length == plainHex.Length)
{
Console.WriteLine("decyryption error");
return;
}
// 4. Convert from hex back to string, if OK
data = Cnv.StringFromHex(dataHex);
Console.WriteLine("Data ='{0}'", data);
This should result in the output:
CryptoSys API Version=400 ENCRYPTION: Key =FEDCBA9876543210 Data ='Some text' In Hex =536F6D652074657874 Input to cipher =536F6D65207465787407070707070707 Ciphertext =5D6216A08F6276896C843DF04052AAF9 DECRYPTION: Key =FEDCBA9876543210 Ciphertext =5D6216A08F6276896C843DF04052AAF9 Output in hex =536F6D65207465787407070707070707 After unpadding =536F6D652074657874 Data ='Some text'
TestAPIvbnetp.zip which should be in the directory
C:\Program Files\CryptoSysAPI\DotNetunless you specified a different folder during installation. See also Module1.vb from the project
CrSysAPIDemoEncrypt also provided
in the installation download.
This page last updated 7 July 2008