Perfect-BCrypt module is a Swift Wrapper of bcrypt
We are transitioning to using JIRA for all bugs and support related issues, therefore the GitHub issues has been disabled.
If you find a mistake, bug, or any other helpful suggestion you'd like to make on the docs please head over to http://jira.perfect.org:8080/servicedesk/customer/portal/1 and raise it.
A comprehensive list of open issues can be found at http://jira.perfect.org:8080/projects/ISS/issues
Add this project as a dependency in your Package.swift file.
.Package(url: "https://github.com/PerfectSideRepos/PerfectBCrypt.git", majorVersion: 3)
Generate a "salt" string, for example, let salt = BCrypt.Salt()
will return something like $2b$12$yfG5ZTnTjg.HcgcI2o6Nhe
Generate shadow by password and salt. For example:
let password = "Kk4DQuMMfZL9o"
let salt = "$2b$04$cVWp4XaNU8a4v1uMRum2SO"
let hashed = try BCrypt.Hash(password, salt: salt)
// the hashed result will be:
// "$2b$04$cVWp4XaNU8a4v1uMRum2SO026BWLIoQMD/TXg5uZV.0P.uO8m3YEm"
Verify a password if matches with the previously generated hash:
guard BCrypt.Check(password, hashed: shadow)) else {
// Access Denied.
}
KDF is used in OpenSSH's newer encrypted private key format:
let derived = try BCrypt.KDF("password", salt: "salt",
desiredKeyBytes: 32, rounds: 4, ignoreFewRounds: true)
// derived will be a 32 byte UInt8 array
// 0x5b, 0xbf, 0x0c, 0xc2, 0x93, 0x58, 0x7f, 0x1c,
// 0x36, 0x35, 0x55, 0x5c, 0x27, 0x79, 0x65, 0x98,
// 0xd4, 0x7e, 0x57, 0x90, 0x71, 0xbf, 0x42, 0x7e,
// 0x9d, 0x8f, 0xbe, 0x84, 0x2a, 0xba, 0x34, 0xd9
For more documentation, please visit perfect.org.