module Trailblazer::Endpoint::Protocol::Controller::Cipher

Public Instance Methods

decrypt_value(ctx, encrypted_value:, cipher_key:, **) click to toggle source
# 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:, **) click to toggle source
# 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