Module: Webhookdb::Crypto
- Defined in:
- lib/webhookdb/crypto.rb
Defined Under Namespace
Classes: Boxed
Class Method Summary collapse
- .bin2hex(s) ⇒ Object
- .cipher ⇒ Object
- .decrypt_value(key, value) ⇒ Boxed
- .encrypt_value(key, value) ⇒ Boxed
- .encryption_key ⇒ Boxed
Class Method Details
.bin2hex(s) ⇒ Object
4 5 6 |
# File 'lib/webhookdb/crypto.rb', line 4 def self.bin2hex(s) return s.unpack1("H*") end |
.cipher ⇒ Object
8 9 10 |
# File 'lib/webhookdb/crypto.rb', line 8 def self.cipher return OpenSSL::Cipher.new("aes-256-cbc") end |
.decrypt_value(key, value) ⇒ Boxed
31 32 33 34 35 36 |
# File 'lib/webhookdb/crypto.rb', line 31 def self.decrypt_value(key, value) cipher = self.cipher.decrypt cipher.key = key.raw dec = cipher.update(value.raw) + cipher.final return Boxed.from_raw(dec) end |
.encrypt_value(key, value) ⇒ Boxed
21 22 23 24 25 26 |
# File 'lib/webhookdb/crypto.rb', line 21 def self.encrypt_value(key, value) cipher = self.cipher.encrypt cipher.key = key.raw enc = cipher.update(value.raw) + cipher.final return Boxed.from_raw(enc) end |
.encryption_key ⇒ Boxed
13 14 15 16 |
# File 'lib/webhookdb/crypto.rb', line 13 def self.encryption_key k = self.cipher.encrypt.random_key return Boxed.from_raw(k) end |