Skip to content

PerfectSideRepos/PerfectBCrypt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Perfect-BCrypt

Get Involed with Perfect!

Star Perfect On Github Stack Overflow Follow Perfect on Twitter Join the Perfect Slack

Swift 4.0 Platforms OS X | Linux License Apache PerfectlySoft Twitter Slack Status

Acknowledgement

Perfect-BCrypt module is a Swift Wrapper of bcrypt

Issues

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

Building

Add this project as a dependency in your Package.swift file.

.Package(url: "https://github.com/PerfectSideRepos/PerfectBCrypt.git", majorVersion: 3)

Quick Start

BCrypt.Salt()

Generate a "salt" string, for example, let salt = BCrypt.Salt() will return something like $2b$12$yfG5ZTnTjg.HcgcI2o6Nhe

BCrypt.Hash()

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"

BCrypt.Check()

Verify a password if matches with the previously generated hash:

guard BCrypt.Check(password, hashed: shadow)) else {
	// Access Denied.
}

BCrypt.KDF()

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

Further Information

For more documentation, please visit perfect.org.