Class: Yodatra::Crypto
- Inherits:
-
Object
- Object
- Yodatra::Crypto
- Defined in:
- lib/yodatra/crypto.rb
Class Method Summary collapse
-
.generate_pbkdf(password, salt = nil) ⇒ Object
Computes the PBKDF2-SHA256 digest of a password using 10000 iterations and the given salt, and return a 32-byte output.
Class Method Details
.generate_pbkdf(password, salt = nil) ⇒ Object
Computes the PBKDF2-SHA256 digest of a password using 10000 iterations and the given salt, and return a 32-byte output. If no salt is given, a random 8-byte salt is generated. The salt is also returned.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/yodatra/crypto.rb', line 8 def generate_pbkdf(password, salt = nil) new_salt = salt iter = 1000 if salt.nil? new_salt = SecureRandom.random_bytes(8) end digest = OpenSSL::Digest::SHA256.new len = digest.digest_length value = OpenSSL::PKCS5.pbkdf2_hmac(password, new_salt, iter, len, digest) [new_salt, value] end |