Class: Authentication::Logic::CryptoProviders::Sha512::V2
- Inherits:
-
Object
- Object
- Authentication::Logic::CryptoProviders::Sha512::V2
- Defined in:
- lib/auth/logic/crypto_providers/sha512/v2.rb
Overview
SHA-512 does not have any practical known attacks against it. However, there are better choices. We recommend transitioning to a more secure, adaptive hashing algorithm, like scrypt.
Class Attribute Summary collapse
-
.join_token ⇒ Object
Returns the value of attribute join_token.
-
.stretches ⇒ Object
The number of times to loop through the encryption.
Class Method Summary collapse
-
.encrypt(*tokens) ⇒ Object
Turns your raw password into a Sha512 hash.
-
.matches?(crypted, *tokens) ⇒ Boolean
Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.
Class Attribute Details
.join_token ⇒ Object
Returns the value of attribute join_token.
14 15 16 |
# File 'lib/auth/logic/crypto_providers/sha512/v2.rb', line 14 def join_token @join_token end |
.stretches ⇒ Object
The number of times to loop through the encryption.
17 18 19 |
# File 'lib/auth/logic/crypto_providers/sha512/v2.rb', line 17 def stretches @stretches ||= 20 end |
Class Method Details
.encrypt(*tokens) ⇒ Object
Turns your raw password into a Sha512 hash.
23 24 25 26 27 28 29 |
# File 'lib/auth/logic/crypto_providers/sha512/v2.rb', line 23 def encrypt(*tokens) digest = tokens.flatten.join(join_token) stretches.times do digest = Digest::SHA512.digest(digest) end digest.unpack1("H*") end |
.matches?(crypted, *tokens) ⇒ Boolean
Does the crypted password match the tokens? Uses the same tokens that were used to encrypt.
33 34 35 |
# File 'lib/auth/logic/crypto_providers/sha512/v2.rb', line 33 def matches?(crypted, *tokens) encrypt(*tokens) == crypted end |