lib/razorpay/utility.rb in razorpay-3.2.1 vs lib/razorpay/utility.rb in razorpay-3.2.2

- old
+ new

@@ -24,10 +24,15 @@ def self.verify_webhook_signature(body, signature, secret) verify_signature(body, signature, secret) end + def self.generate_onboarding_signature(body, secret) + json_data = body.to_json + encrypt(json_data, secret); + end + class << self private def verify_signature(data, signature, secret) expected_signature = OpenSSL::HMAC.hexdigest('SHA256', secret, data) @@ -49,9 +54,28 @@ i += 1 r |= v ^ l[i] end r.zero? + end + + def encrypt(data, secret) + iv = secret[0, 12] + key = secret[0, 16] + + cipher = OpenSSL::Cipher.new('aes-128-gcm') + cipher.encrypt + cipher.key = key + cipher.iv = iv + + cipher.auth_data = "" + + encrypted = cipher.update(data) + cipher.final + + tag = cipher.auth_tag + combined_encrypted_data = encrypted + tag + + encrypted_data_hex = combined_encrypted_data.unpack1("H*") end end end end