CryptAPI
home
Features
Documentation
About us
Example
Download
Contact us
index » Example
Example
CryptServiceProvider is the main class to use, this class implements a service provider for all the supported cryptographic algorithms.

In this example we print the hash of a string encrypted with MD5

using System;
using CryptAPI;

public class Example1 {
 public static void Main(string[] args)
 {
    CryptServiceProvider provider = new CryptServiceProvider(Algorithm.MD5);
    HashAlgorithm md5 = provider.GetCryptServiceProvider();
    Console.WriteLine(md5.Encrypt("Hello MD5"));
 }
}

And now with BlowFish

    ...
    CryptServiceProvider provider = new CryptServiceProvider();
    HashAlgorithm bf = provider.GetCryptServiceProvider(Algorithm.BF);
    string salt = "Averyveryveryveryverylongstring";
    Console.WriteLine(bf.Encrypt("Top Secret",salt));
    ...

We also provide two useful utilities, a random password generator and a random salt generator the next example shows how to use both

    ...
    PasswordRandomGenerator ea = new PasswordRandomGenerator();
    Console.WriteLine("Random password of length 8: "+ea.CreateRandomString(8,8));

    SaltRandomGenerator eaea = new SaltRandomGenerator();
    Console.WriteLine("Blowfish Salt " + eaea.CreateRandomString(22,22));
    Console.WriteLine("MD5 Salt " + eaea.CreateRandomString(16,16));
    Console.WriteLine("DES Salt " + eaea.CreateRandomString(8,8));
    ...