Class: EzCrypto::Digester
- Inherits:
-
Object
- Object
- EzCrypto::Digester
- Defined in:
- lib/ezcrypto.rb
Class Method Summary collapse
- .digest(data, size = 16) ⇒ Object
- .digest64(data, size = 16) ⇒ Object
- .generate_hexkey(size = 40) ⇒ Object
- .generate_key(size = 16) ⇒ Object
- .generate_key64(size = 32) ⇒ Object
-
.get_key(password, salt, size) ⇒ Object
Various handy Digest methods.
- .hexdigest(data, size = 40) ⇒ Object
Class Method Details
.digest(data, size = 16) ⇒ Object
579 580 581 582 583 584 585 586 587 |
# File 'lib/ezcrypto.rb', line 579 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, size = 16) ⇒ Object
605 606 607 |
# File 'lib/ezcrypto.rb', line 605 def self.digest64(data,size=16) Base64.encode64(digest(data,size)) end |
.generate_hexkey(size = 40) ⇒ Object
571 572 573 574 |
# File 'lib/ezcrypto.rb', line 571 def self.generate_hexkey(size=40) key=OpenSSL::Random.random_bytes(size) hexdigest(key,size) end |
.generate_key(size = 16) ⇒ Object
556 557 558 559 |
# File '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/ezcrypto.rb', line 564 def self.generate_key64(size=32) key=OpenSSL::Random.random_bytes(size) digest64(key,size) end |
.get_key(password, salt, size) ⇒ Object
Various handy Digest methods.
Warning! The interface may change.
549 550 551 |
# File 'lib/ezcrypto.rb', line 549 def self.get_key(password,salt,size) digest(salt+password,size) end |
.hexdigest(data, size = 40) ⇒ Object
592 593 594 595 596 597 598 599 600 |
# File 'lib/ezcrypto.rb', line 592 def self.hexdigest(data,size=40) if size==0 "" elsif size<=40 Digest::SHA1.hexdigest(data)[0..(size-1)] else Digest::SHA256.hexdigest(data)[0..(size-1)] end end |