/// <inheritdoc /> public override string GenerateSalt(CrypterOptions options) { Check.Null("options", options); int rounds = options.GetValue(CrypterOption.Rounds, 6); Check.Range("CrypterOption.Rounds", rounds, MinRounds, MaxRounds); string prefix; switch (options.GetValue(CrypterOption.Variant, BlowfishCrypterVariant.Unspecified)) { case BlowfishCrypterVariant.Unspecified: prefix = "$2a$"; break; case BlowfishCrypterVariant.Compatible: prefix = "$2x$"; break; case BlowfishCrypterVariant.Corrected: prefix = "$2y$"; break; default: throw Exceptions.ArgumentOutOfRange("CrypterOption.Variant", "Unknown variant."); } return(prefix + rounds.ToString("00") + '$' + Base64Encoding.Blowfish.GetString(Security.GenerateRandomBytes(16))); }
/// <inheritdoc /> public override string GenerateSalt(CrypterOptions options) { Check.Null("options", options); int rounds = options.GetValue(CrypterOption.Rounds, 14); Check.Range("CrypterOption.Rounds", rounds, MinRounds, MaxRounds); string prefix; switch (options.GetValue(CrypterOption.Variant, PhpassCrypterVariant.Standard)) { case PhpassCrypterVariant.Standard: prefix = "$P$"; break; case PhpassCrypterVariant.Phpbb: prefix = "$H$"; break; case PhpassCrypterVariant.Drupal: prefix = "$S$"; break; default: throw Exceptions.ArgumentOutOfRange("CrypterOption.Variant", "Unknown variant."); } return(prefix + Base64Encoding.UnixMD5.GetChar(rounds) + Base64Encoding.UnixMD5.GetString(Security.GenerateRandomBytes(6))); }
/// <inheritdoc /> public override string GenerateSalt(CrypterOptions options) { Check.Null("options", options); int?rounds = options.GetValue <int?>(CrypterOption.Rounds); if (rounds != null) { Check.Range("CrypterOption.Rounds", (int)rounds, MinRounds, MaxRounds); } byte[] roundsBytes = new byte[3], saltBytes = null; try { BitPacking.LEBytesFromUInt24((uint)(rounds ?? 4321), roundsBytes, 0); saltBytes = Security.GenerateRandomBytes(3); return("_" + Base64Encoding.UnixMD5.GetString(roundsBytes) + Base64Encoding.UnixMD5.GetString(saltBytes)); } finally { Security.Clear(roundsBytes); Security.Clear(saltBytes); } }
/// <inheritdoc /> public override string GenerateSalt(CrypterOptions options) { Check.Null("options", options); switch (options.GetValue(CrypterOption.Variant, LdapCrypterVariant.SSha)) { case LdapCrypterVariant.Crypt: Crypter crypter = options.GetValue <Crypter>(LdapCrypterOption.Crypter); if (crypter == null) { throw Exceptions.Argument("LdapCrypterOption.Crypter", "Crypter not set. Did you intend Crypter.TraditionalDes (the slappasswd default)?"); } CrypterOptions crypterOptions = options.GetValue(LdapCrypterOption.CrypterOptions, CrypterOptions.None); return("{CRYPT}" + crypter.GenerateSalt(crypterOptions)); case LdapCrypterVariant.SSha512: return("{SSHA512}" + GenerateSaltString()); case LdapCrypterVariant.SSha384: return("{SSHA384}" + GenerateSaltString()); case LdapCrypterVariant.SSha256: return("{SSHA256}" + GenerateSaltString()); case LdapCrypterVariant.SSha: return("{SSHA}" + GenerateSaltString()); case LdapCrypterVariant.SMD5: return("{SMD5}" + GenerateSaltString()); case LdapCrypterVariant.Sha512: return("{SHA512}"); case LdapCrypterVariant.Sha384: return("{SHA384}"); case LdapCrypterVariant.Sha256: return("{SHA256}"); case LdapCrypterVariant.Sha: return("{SHA}"); case LdapCrypterVariant.MD5: return("{MD5}"); case LdapCrypterVariant.Cleartext: return("{CLEARTEXT}"); default: throw Exceptions.ArgumentOutOfRange("CrypterOption.Variant", "Unknown variant."); } }
/// <inheritdoc /> public override string GenerateSalt(CrypterOptions options) { Check.Null("options", options); int?rounds = options.GetValue <int?>(CrypterOption.Rounds); if (rounds != null) { Check.Range("CrypterOption.Rounds", (int)rounds, MinRounds, MaxRounds); } return(CryptPrefix + (rounds != null ? string.Format("rounds={0}$", rounds) : "") + Base64Encoding.UnixMD5.GetString(Security.GenerateRandomBytes(12))); }
/// <inheritdoc /> public override string GenerateSalt(CrypterOptions options) { Check.Null("options", options); string prefix; switch (options.GetValue(CrypterOption.Variant, MD5CrypterVariant.Standard)) { case MD5CrypterVariant.Standard: prefix = "$1$"; break; case MD5CrypterVariant.Apache: prefix = "$apr1$"; break; default: throw Exceptions.ArgumentOutOfRange("CrypterOption.Variant", "Unknown variant."); } return(prefix + Base64Encoding.UnixMD5.GetString(Security.GenerateRandomBytes(6))); }