Crypter Class

CryptSharp

Crypter Class CryptSharp
Crypts and verifies passwords. The main class for most uses of this library.
Inheritance Hierarchy

SystemObject  CryptSharpCrypter
    More...

Namespace: CryptSharp
Assembly: CryptSharp (in CryptSharp.dll) Version: 2.1.0.0
Syntax

public abstract class Crypter
Public MustInherit Class Crypter
public ref class Crypter abstract
[<AbstractClassAttribute>]
type Crypter =  class end

The Crypter type exposes the following members.

Methods

  NameDescription
Public methodCanCrypt
Checks if the particular crypt algorithm is compatible with the salt string or crypted password.
Public methodStatic memberCheckPassword(Byte, String)
Checks if the crypted password matches the given password bytes.
Public methodStatic memberCheckPassword(String, String)
Checks if the crypted password matches the given password string.
Public methodCrypt(Byte)
Creates a one-way password hash (crypted password) from password bytes.
Public methodCrypt(String)
Creates a one-way password hash (crypted password) from a password string.
Public methodCrypt(Byte, CrypterOptions)
Creates a one-way password hash (crypted password) from password bytes. Options modify the crypt operation.
Public methodCrypt(Byte, String)
Creates a one-way password hash (crypted password) from password bytes and a salt string. The salt can be produced using GenerateSalt(CrypterOptions). Because crypted passwords take the form algorithm+salt+hash, if you pass a crypted password as the salt parameter, the same algorithm and salt will be used to re-crypt the password. Since randomness comes from the salt, the same salt means the same hash, and so the same crypted password will result. Therefore, this method can both generate *and* verify crypted passwords.
Public methodCrypt(String, CrypterOptions)
Creates a one-way password hash (crypted password) from a password string. Options modify the crypt operation.
Public methodCrypt(String, String)
Creates a one-way password hash (crypted password) from a password string and a salt string. The salt can be produced using GenerateSalt(CrypterOptions). Because crypted passwords take the form algorithm+salt+hash, if you pass a crypted password as the salt parameter, the same algorithm and salt will be used to re-crypt the password. Since randomness comes from the salt, the same salt means the same hash, and so the same crypted password will result. Therefore, this method can both generate *and* verify crypted passwords.
Public methodGenerateSalt
Generates a salt string with default options. The purpose of salt is to make dictionary attacks against a whole password database much harder, by causing the crypted password to be different even if two users have the same uncrypted password.
Public methodGenerateSalt(Int32)
Generates a salt string using the specified number of rounds. The purpose of salt is to make dictionary attacks against a whole password database much harder, by causing the crypted password to be different even if two users have the same uncrypted password.
Public methodGenerateSalt(CrypterOptions)
Generates a salt string. Options are used to modify the salt generation. The purpose of salt is to make dictionary attacks against a whole password database much harder, by causing the crypted password to be different even if two users have the same uncrypted password. Randomness in a crypted password comes from its salt string, as do all recorded options. The same salt string, when combined with the same password, will generate the same crypted password. If the salt string differs, the same password will generate a different crypted password (crypted passwords have the form algorithm+salt+hash, so the salt is always carried along with the crypted password).
Public methodStatic memberGetCrypter
Searches for a crypt algorithm compatible with the specified crypted password or prefix.
Top
Properties

  NameDescription
Public propertyStatic memberBlowfish
Blowfish crypt, sometimes called BCrypt. A very good choice.
Public propertyStatic memberExtendedDes
Extended DES crypt.
Public propertyStatic memberLdap
LDAP schemes such as {SHA}.
Public propertyStatic memberMD5
MD5 crypt, supported by nearly all systems. A variant supports Apache htpasswd files.
Public propertyStatic memberPhpass
PHPass crypt. Used by WordPress. Variants support phpBB and Drupal 7+.
Public propertyProperties
Properties inherent to the particular crypt algorithm. These cannot be modified. See CrypterProperty for possible keys.
Public propertyStatic memberSha256
SHA256 crypt. A reasonable choice if you cannot use Blowfish crypt for policy reasons.
Public propertyStatic memberSha512
SHA512 crypt. A reasonable choice if you cannot use Blowfish crypt for policy reasons.
Public propertyStatic memberTraditionalDes
Traditional DES crypt.
Top
Examples

Crypting a Password
using CryptSharp;

// Crypt using the Blowfish crypt ("BCrypt") algorithm.
string cryptedPassword = Crypter.Blowfish.Crypt(password);
Checking a Password
using CryptSharp;

// Do the passwords match?
// You can also check a password using the Crypt method, but this approach way is easier.
bool matches = Crypter.CheckPassword(testPassword, cryptedPassword);
Specifying Options
using CryptSharp;

// Specify the $apr1$ Apache htpasswd variant of the MD5 crypt algorithm.
string cryptedPassword = Crypter.MD5.Crypt(password, new CrypterOptions()
    {
        { CrypterOption.Variant, MD5CrypterVariant.Apache }
    });
See Also

Reference

Inheritance Hierarchy

SystemObject
  CryptSharpCrypter
    CryptSharpBlowfishCrypter
    CryptSharpExtendedDesCrypter
    CryptSharpLdapCrypter
    CryptSharpMD5Crypter
    CryptSharpPhpassCrypter
    CryptSharpShaCrypter
    CryptSharpTraditionalDesCrypter