项目作者: PerfectSideRepos

项目描述 :
Swift Wrapper of bcrypt (BlowFish)
高级语言: C
项目地址: git://github.com/PerfectSideRepos/PerfectBCrypt.git
创建时间: 2017-10-18T15:13:42Z
项目社区:https://github.com/PerfectSideRepos/PerfectBCrypt

开源协议:

下载


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.

  1. .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:

  1. let password = "Kk4DQuMMfZL9o"
  2. let salt = "$2b$04$cVWp4XaNU8a4v1uMRum2SO"
  3. let hashed = try BCrypt.Hash(password, salt: salt)
  4. // the hashed result will be:
  5. // "$2b$04$cVWp4XaNU8a4v1uMRum2SO026BWLIoQMD/TXg5uZV.0P.uO8m3YEm"

BCrypt.Check()

Verify a password if matches with the previously generated hash:

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

BCrypt.KDF()

KDF is used in OpenSSH’s newer encrypted private key format:

  1. let derived = try BCrypt.KDF("password", salt: "salt",
  2. desiredKeyBytes: 32, rounds: 4, ignoreFewRounds: true)
  3. // derived will be a 32 byte UInt8 array
  4. // 0x5b, 0xbf, 0x0c, 0xc2, 0x93, 0x58, 0x7f, 0x1c,
  5. // 0x36, 0x35, 0x55, 0x5c, 0x27, 0x79, 0x65, 0x98,
  6. // 0xd4, 0x7e, 0x57, 0x90, 0x71, 0xbf, 0x42, 0x7e,
  7. // 0x9d, 0x8f, 0xbe, 0x84, 0x2a, 0xba, 0x34, 0xd9

Further Information

For more documentation, please visit perfect.org.