Top Description Fields Constructors Methods
org.bouncycastle.crypto.generators

public Class OpenBSDBCrypt

extends Object
Class Inheritance
Imports
java.io.ByteArrayOutputStream, java.util.HashSet, .Set, org.bouncycastle.crypto.DataLengthException, org.bouncycastle.util.Arrays, .Strings

Password hashing scheme BCrypt, designed by Niels Provos and David Mazières, using the String format and the Base64 encoding of the reference implementation on OpenBSD.

Passwords are encoded using UTF-8 when provided as char[]. Encoded passwords longer than 72 bytes are truncated and all remaining bytes are ignored.

Field Summary

Modifier and TypeField and Description
private static final Set<String>
private static final byte[]
private static final String
private static final byte[]

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static boolean

Returns:

true if the password corresponds to the Bcrypt String, otherwise false
checkPassword
(String
a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$'
bcryptString
,
char[]
the password as an array of chars
password
)

Checks if a password corresponds to a 60 character Bcrypt String

public static boolean

Returns:

true if the password corresponds to the Bcrypt String, otherwise false
checkPassword
(String
a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$'
bcryptString
,
byte[]
the password as an array of bytes
password
)

Checks if a password corresponds to a 60 character Bcrypt String

private static String

Returns:

a 60 character Bcrypt String
createBcryptString
(String
the version, 2y,2b or 2a. (2a is not backwards compatible.)
version
,
byte[]
the password
password
,
byte[]
a 16 byte salt
salt
,
int
the cost factor, treated as an exponent of 2
cost
)

Creates a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$'

private static byte[]
private static boolean

Returns:

true if the password corresponds to the Bcrypt String, otherwise false
doCheckPassword
(String
a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$'
bcryptString
,
byte[]
the password as an array of chars
password
)

Checks if a password corresponds to a 60 character Bcrypt String

private static String

Returns:

a 60 character Bcrypt String
doGenerate
(String
the version, may be 2b, 2y or 2a. (2a is not backwards compatible.)
version
,
byte[]
the password
psw
,
byte[]
a 16 byte salt
salt
,
int
the cost factor, treated as an exponent of 2
cost
)

Creates a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$'

private static void
encodeData(StringBuilder sb, byte[] data)

public static String

Returns:

a 60 character Bcrypt String
generate
(char[]
the password
password
,
byte[]
a 16 byte salt
salt
,
int
the cost factor, treated as an exponent of 2
cost
)

Creates a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$' using version '2y'.

public static String

Returns:

a 60 character Bcrypt String
generate
(byte[]
the password
password
,
byte[]
a 16 byte salt
salt
,
int
the cost factor, treated as an exponent of 2
cost
)

Creates a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$' using version '2y'.

public static String

Returns:

a 60 character Bcrypt String
generate
(String
the version, may be 2b, 2y or 2a. (2a is not backwards compatible.)
version
,
char[]
the password
password
,
byte[]
a 16 byte salt
salt
,
int
the cost factor, treated as an exponent of 2
cost
)

Creates a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$'

public static String

Returns:

a 60 character Bcrypt String
generate
(String
the version, may be 2b, 2y or 2a. (2a is not backwards compatible.)
version
,
byte[]
the password already encoded as a byte array.
password
,
byte[]
a 16 byte salt
salt
,
int
the cost factor, treated as an exponent of 2
cost
)

Creates a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$'

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allowedVersionsback to summary
private static final Set<String> allowedVersions
decodingTableback to summary
private static final byte[] decodingTable
defaultVersionback to summary
private static final String defaultVersion
encodingTableback to summary
private static final byte[] encodingTable

Constructor Detail

OpenBSDBCryptback to summary
private OpenBSDBCrypt()

Method Detail

checkPasswordback to summary
public static boolean checkPassword(String bcryptString, char[] password)

Checks if a password corresponds to a 60 character Bcrypt String

Parameters
bcryptString:String

a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$'

password:char[]

the password as an array of chars

Returns:boolean

true if the password corresponds to the Bcrypt String, otherwise false

checkPasswordback to summary
public static boolean checkPassword(String bcryptString, byte[] password)

Checks if a password corresponds to a 60 character Bcrypt String

Parameters
bcryptString:String

a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$'

password:byte[]

the password as an array of bytes

Returns:boolean

true if the password corresponds to the Bcrypt String, otherwise false

createBcryptStringback to summary
private static String createBcryptString(String version, byte[] password, byte[] salt, int cost)

Creates a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$'

Parameters
version:String

the version, 2y,2b or 2a. (2a is not backwards compatible.)

password:byte[]

the password

salt:byte[]

a 16 byte salt

cost:int

the cost factor, treated as an exponent of 2

Returns:String

a 60 character Bcrypt String

decodeSaltStringback to summary
private static byte[] decodeSaltString(String saltString)
doCheckPasswordback to summary
private static boolean doCheckPassword(String bcryptString, byte[] password)

Checks if a password corresponds to a 60 character Bcrypt String

Parameters
bcryptString:String

a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$'

password:byte[]

the password as an array of chars

Returns:boolean

true if the password corresponds to the Bcrypt String, otherwise false

doGenerateback to summary
private static String doGenerate(String version, byte[] psw, byte[] salt, int cost)

Creates a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$'

Parameters
version:String

the version, may be 2b, 2y or 2a. (2a is not backwards compatible.)

psw:byte[]

the password

salt:byte[]

a 16 byte salt

cost:int

the cost factor, treated as an exponent of 2

Returns:String

a 60 character Bcrypt String

encodeDataback to summary
private static void encodeData(StringBuilder sb, byte[] data)
generateback to summary
public static String generate(char[] password, byte[] salt, int cost)

Creates a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$' using version '2y'.

Parameters
password:char[]

the password

salt:byte[]

a 16 byte salt

cost:int

the cost factor, treated as an exponent of 2

Returns:String

a 60 character Bcrypt String

generateback to summary
public static String generate(byte[] password, byte[] salt, int cost)

Creates a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$' using version '2y'.

Parameters
password:byte[]

the password

salt:byte[]

a 16 byte salt

cost:int

the cost factor, treated as an exponent of 2

Returns:String

a 60 character Bcrypt String

generateback to summary
public static String generate(String version, char[] password, byte[] salt, int cost)

Creates a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$'

Parameters
version:String

the version, may be 2b, 2y or 2a. (2a is not backwards compatible.)

password:char[]

the password

salt:byte[]

a 16 byte salt

cost:int

the cost factor, treated as an exponent of 2

Returns:String

a 60 character Bcrypt String

generateback to summary
public static String generate(String version, byte[] password, byte[] salt, int cost)

Creates a 60 character Bcrypt String, including version, cost factor, salt and hash, separated by '$'

Parameters
version:String

the version, may be 2b, 2y or 2a. (2a is not backwards compatible.)

password:byte[]

the password already encoded as a byte array.

salt:byte[]

a 16 byte salt

cost:int

the cost factor, treated as an exponent of 2

Returns:String

a 60 character Bcrypt String