Module: Trailblazer::Endpoint::Protocol::Controller::Cipher
- Defined in:
- lib/trailblazer/endpoint/protocol/cipher.rb
Overview
FIXME: copied from Tyrant!
Class Method Summary collapse
- .decrypt_value(ctx, encrypted_value:, cipher_key:) ⇒ Object
- .encrypt_value(ctx, value:, cipher_key:) ⇒ Object
Class Method Details
.decrypt_value(ctx, encrypted_value:, cipher_key:) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/trailblazer/endpoint/protocol/cipher.rb', line 17 def decrypt_value(ctx, encrypted_value:, cipher_key:, **) cipher = OpenSSL::Cipher.new('DES-EDE3-CBC').decrypt cipher.key = Digest::SHA1.hexdigest(cipher_key)[0..23] s = [encrypted_value].pack("H*").unpack("C*").pack("c*") ctx[:decrypted_value] = cipher.update(s) + cipher.final end |
.encrypt_value(ctx, value:, cipher_key:) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/trailblazer/endpoint/protocol/cipher.rb', line 9 def encrypt_value(ctx, value:, cipher_key:, **) cipher = OpenSSL::Cipher.new('DES-EDE3-CBC').encrypt cipher.key = Digest::SHA1.hexdigest(cipher_key)[0..23] # ArgumentError: key must be 24 bytes s = cipher.update(value) + cipher.final ctx[:encrypted_value] = s.unpack('H*')[0].upcase end |