-
Notifications
You must be signed in to change notification settings - Fork 1
Bcrypt
paulofaria edited this page Feb 2, 2021
·
1 revision
public enum Bcryptpublic static func hash(_ plaintext: String, cost: Int = 12) throws -> Stringpublic static func hash(_ plaintext: String, salt: String) throws -> StringVerifies an existing BCrypt hash matches the supplied plaintext value. Verification works by parsing the salt and version from
the existing digest and using that information to hash the plaintext data. If hash digests match, this method returns true.
public static func verify(_ plaintext: String, against hash: String) throws -> Boollet hash = try BCrypt.hash("password", cost: 4)
try BCrypt.verify("password", against: hash) // true
try BCrypt.verify("foo", created: hash) // false
- plaintext: Plaintext data to digest and verify.
- hash: Existing BCrypt hash to parse version, salt, and existing digest from.
CryptoError if hashing fails or if data conversion fails.
true if the hash was created from the supplied plaintext data.
Generates string (29 chars total) containing the algorithm information + the cost + base-64 encoded 22 character salt
public static func generateSalt(cost: Int, algorithm: Algorithm = ._2b, seed: [UInt8]? = nil) -> StringE.g: $2b$05$J/dtt5ybYUTCJ/dtt5ybYO
$AA$ => Algorithm
$CC$ => Cost
SSSSSSSSSSSSSSSSSSSSSS => Salt
Allowed charset for the salt: [./A-Za-z0-9]
- cost: Desired complexity. Larger
costvalues take longer to hash and verify. - algorithm: Revision to use (2b by default)
- seed: Salt (without revision data). Generated if not provided. Must be 16 chars long.
Complete salt
Generated at 2021-04-21T13:08:01+0000 using swift-doc 1.0.0-beta.5.
Types
- BuyName
- BuyNameMessage
- DeleteName
- DeleteNameMessage
- GenesisState
- GetWhois
- KeysOptions
- ListWhois
- NameServiceApp
- NameServiceAppModule
- NameServiceAppModuleBasic
- NameServiceKeeper
- NameServiceKeys
- QueryCommand
- QueryNameserviceCommand
- ResolveName
- SetName
- SetNameMessage
- TransactionCommand
- TransactionNameserviceCommand
- Whois