File: bcrypt_pbkdf.rb

package info (click to toggle)
ruby-bcrypt-pbkdf 1.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 196 kB
  • sloc: ansic: 1,062; ruby: 72; makefile: 4
file content (24 lines) | stat: -rw-r--r-- 706 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
begin
  RUBY_VERSION =~ /(\d+.\d+)/
  require "#{$1}/bcrypt_pbkdf_ext"
rescue LoadError
  require "bcrypt_pbkdf_ext"
end

module BCryptPbkdf
  # generates a key from a password + salt returning a string with keylen bytes
  # that can be used as cryptographic key.
  #
  # Remember to get a good random salt of at least 16 bytes.  Using a higher
  # rounds count will increase the cost of an exhaustive search but will also
  # make derivation proportionally slower.
  #
  # Example:
  #   rounds = 10
  #   keylen = 64
  #   @key = BCryptPbkdf.key("my secret", "my salt", keylen, rounds)
  def self.key(pass,salt,keylen,rounds)
    BCryptPbkdf::Engine::__bc_crypt_pbkdf(pass,salt,keylen,rounds)
  end
end