Module: EncryptableHelper
- Included in:
- Api::Admin::Concerns::Authentication, Api::Aoa::V1::AuthenticationController, Api::Aoa::V1::ReservationsController, Api::V5::ReservationsController, Api::V5::ReviewsController, Api::Vendor::V1::Concerns::Authentication, Api::Vendor::V1::Klook::BaseController, ReservationService::Form::Base
- Defined in:
- app/helpers/encryptable_helper.rb
Overview
typed: false frozen_string_literal: true
Instance Method Summary collapse
- #decrypt(value) ⇒ Object
- #encrypt(value) ⇒ Object
- #generate_signature(secret_key, timestamp) ⇒ Object
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, ) 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? "#{}\r\n#{http_verb}\r\n#{path}\r\n\r\n#{payload}" else "#{}\r\n#{http_verb}\r\n#{path}\r\n\r\n" end OpenSSL::HMAC.hexdigest('sha256', secret_key, raw_signature) end |