Class: EzCrypto::Digester
- Inherits:
-
Object
- Object
- EzCrypto::Digester
- Defined in:
- lib/gems/ezcrypto-0.7/lib/ezcrypto.rb
Class Method Summary collapse
- .digest(data, size = 16) ⇒ Object
- .digest64(data) ⇒ Object
- .generate_key(size = 16) ⇒ Object
- .generate_key64(size = 32) ⇒ Object
-
.get_key(password, salt, size) ⇒ Object
Various handy Digest methods.
Class Method Details
.digest(data, size = 16) ⇒ Object
572 573 574 575 576 577 578 579 580 |
# File 'lib/gems/ezcrypto-0.7/lib/ezcrypto.rb', line 572 def self.digest(data,size=16) if size==0 "" elsif size<=16 Digest::SHA1.digest(data)[0..(size-1)] else Digest::SHA256.digest(data)[0..(size-1)] end end |
.digest64(data) ⇒ Object
585 586 587 |
# File 'lib/gems/ezcrypto-0.7/lib/ezcrypto.rb', line 585 def self.digest64(data) Base64.encode64(digest(data)) end |
.generate_key(size = 16) ⇒ Object
556 557 558 559 |
# File 'lib/gems/ezcrypto-0.7/lib/ezcrypto.rb', line 556 def self.generate_key(size=16) key=OpenSSL::Random.random_bytes(size) digest(key,size) end |
.generate_key64(size = 32) ⇒ Object
564 565 566 567 |
# File 'lib/gems/ezcrypto-0.7/lib/ezcrypto.rb', line 564 def self.generate_key64(size=32) key=OpenSSL::Random.random_bytes(size) digest(key,size) end |
.get_key(password, salt, size) ⇒ Object
Various handy Digest methods.
Warning! The interface may change.
549 550 551 |
# File 'lib/gems/ezcrypto-0.7/lib/ezcrypto.rb', line 549 def self.get_key(password,salt,size) digest(salt+password,size) end |