BCrypt class
BCrypt implements OpenBSD-style Blowfish password hashing using the scheme described in "A Future-Adaptable Password Scheme" by Niels Provos and David Mazieres.
This password hashing system tries to thwart off-line password cracking using a computationally-intensive hashing algorithm, based on Bruce Schneier's Blowfish cipher. The work factor of the algorithm is parameterised, so it can be increased as computers get faster.
Usage is really simple. To hash a password for the first time, call the hashpw method with a random salt, like this:
String pw_hash = BCrypt.hashpw(plain_password, BCrypt.gensalt());
To check whether a plaintext password matches one that has been hashed previously, use the checkpw method:
if (BCrypt.checkpw(candidate_password, stored_hash))
System.out.println("It matches");
else
System.out.println("It does not match");
The gensalt() method takes an optional parameter (log_rounds) that determines the computational complexity of the hashing:
String strong_salt = BCrypt.gensalt(10)
String stronger_salt = BCrypt.gensalt(12)
The amount of work increases exponentially (2**log_rounds), so each increment is twice as much work. The default log_rounds is 10, and the valid range is 4 to 30.
@author Damien Miller @version 0.2
Constructors
- BCrypt()
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- P → Uint32List
-
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- S → Uint32List
-
final
Methods
-
encipher(
Uint32List leftRight, int arrayOffset) → void -
Blowfish encipher a single 64-bit block encoded as
two 32-bit halves with the
leftRightarray that contains the two 32-bit half blocks andarrayOffsetas the position in the array of the blocks. -
encryptRaw(
Uint8List password, Uint8List salt, int logRounds, Uint32List cdata) → Uint8List -
hash(
Uint8List hpass, Uint8List hsalt) → Uint8List -
Creates a combined hash code for a number of objects.
override
-
initKey(
) → void -
key(
Uint8List key) → void -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
-
base64Code
→ List<
String> -
final
- bcryptSaltLen → int
-
final
- bfCryptCiphertext → Uint32List
-
final
- blowfishNumRounds → int
-
final
- index64 → Uint8List
-
final
- openbsdInitialVector → Uint32List
-
final
-
pOrig
→ List<
int> -
final
-
sOrig
→ List<
int> -
final
Static Methods
-
checkPassword(
String plaintext, String hashed) → bool -
generateSalt(
{int logRounds = gensaltDefaultLog2Rounds, Random? random}) → String -
hashPassword(
String password, String salt) → String -
This method takes a
passwordand returns a hash calculated with the bcrypt algorithm. Thesaltis added to enlarge the hash base -
streamtoword(
Uint8List data, Uint8List offp) → int
Constants
- gensaltDefaultLog2Rounds → const int