DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Static Public Member Functions | Properties | List of all members
Deveel.Data.Security.PasswordCrypto Class Reference

Public Member Functions

 PasswordCrypto (string hashName, int keyLength)
 
string Hash (string password, out string salt)
 
bool Verify (string hashedPassword, string password, string salt)
 
override string ToString ()
 

Static Public Member Functions

static PasswordCrypto Parse (string defString)
 

Properties

string HashName [get, private set]
 
int KeyLength [get, private set]
 
IKeyedHashFunction HashFunction [get, set]
 

Detailed Description

Definition at line 21 of file PasswordCrypto.cs.

Constructor & Destructor Documentation

Deveel.Data.Security.PasswordCrypto.PasswordCrypto ( string  hashName,
int  keyLength 
)
inline

Definition at line 22 of file PasswordCrypto.cs.

22  {
23  KeyLength = keyLength;
24  HashName = hashName;
25 
26  var hash = HashFunctions.GetFunction(hashName);
27  if (hash == null)
28  throw new ArgumentException(String.Format("Hash function {0} is not supported.", hashName));
29  if (!(hash is IKeyedHashFunction))
30  throw new ArgumentException(String.Format("Hash function {0} does not handle keys.", hashName));
31 
32  HashFunction = hash as IKeyedHashFunction;
33  }
A long string in the system.

Member Function Documentation

string Deveel.Data.Security.PasswordCrypto.Hash ( string  password,
out string  salt 
)
inline

Definition at line 41 of file PasswordCrypto.cs.

41  {
42  salt = HashFunction.GenerateSaltString();
43  return HashFunction.MakePbkdf2String(password, salt, 32);
44  }
static PasswordCrypto Deveel.Data.Security.PasswordCrypto.Parse ( string  defString)
inlinestatic

Definition at line 54 of file PasswordCrypto.cs.

54  {
55  if (String.IsNullOrEmpty(defString))
56  throw new ArgumentNullException("defString");
57 
58  var sIndex = defString.IndexOf('(');
59  if (sIndex == -1)
60  throw new FormatException();
61 
62  var eIndex = defString.IndexOf(')');
63  if (eIndex == -1)
64  throw new FormatException();
65 
66  var hashName = defString.Substring(0, sIndex);
67  var sKeyLength = defString.Substring(sIndex + 1, eIndex - (sIndex + 1));
68 
69  hashName = hashName.Trim();
70 
71  if (String.IsNullOrEmpty(hashName))
72  throw new FormatException();
73 
74  int keyLength;
75  if (!Int32.TryParse(sKeyLength, out keyLength))
76  throw new FormatException();
77 
78  return new PasswordCrypto(hashName, keyLength);
79  }
A long string in the system.
PasswordCrypto(string hashName, int keyLength)
override string Deveel.Data.Security.PasswordCrypto.ToString ( )
inline

Definition at line 50 of file PasswordCrypto.cs.

50  {
51  return String.Format("{0}({1})", HashName, KeyLength);
52  }
A long string in the system.
bool Deveel.Data.Security.PasswordCrypto.Verify ( string  hashedPassword,
string  password,
string  salt 
)
inline

Definition at line 46 of file PasswordCrypto.cs.

46  {
47  return HashFunction.VerifyPbkdf2String(hashedPassword, password, salt);
48  }

Property Documentation

IKeyedHashFunction Deveel.Data.Security.PasswordCrypto.HashFunction
getsetprivate

Definition at line 39 of file PasswordCrypto.cs.

string Deveel.Data.Security.PasswordCrypto.HashName
getprivate set

Definition at line 35 of file PasswordCrypto.cs.

int Deveel.Data.Security.PasswordCrypto.KeyLength
getprivate set

Definition at line 37 of file PasswordCrypto.cs.


The documentation for this class was generated from the following file: