Module: EncryptableHelper

Overview

typed: false frozen_string_literal: true

Instance Method Summary collapse

Instance Method Details

#decrypt(value) ⇒ Object



9
10
11
# File 'app/helpers/encryptable_helper.rb', line 9

def decrypt(value)
  Base64.strict_decode64(value)
end

#encrypt(value) ⇒ Object



5
6
7
# File 'app/helpers/encryptable_helper.rb', line 5

def encrypt(value)
  Base64.strict_encode64(value)
end

#generate_signature(secret_key, timestamp) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/encryptable_helper.rb', line 13

def generate_signature(secret_key, timestamp)
  http_verb = request.method
  path = request.fullpath
  # Read the request body and rewind so Rails can read it again
  payload = request.body.read
  request.body.rewind

  raw_signature = if payload.present?
                    "#{timestamp}\r\n#{http_verb}\r\n#{path}\r\n\r\n#{payload}"
                  else
                    "#{timestamp}\r\n#{http_verb}\r\n#{path}\r\n\r\n"
                  end

  OpenSSL::HMAC.hexdigest('sha256', secret_key, raw_signature)
end