Module: KHL::Webhook
- Defined in:
- lib/khl/webhook.rb
Overview
# Rails Environment params = KHL::Webhook.decompress(request.body.string) encrypted_data = params raw_json = KHL::Webhook.decode(“your_encrypt_key”, encrypted_data) message = KHL::Message.parse(raw_json)
Class Method Summary collapse
-
.decode(encrypt_key, encrypted_data) ⇒ String
Decode the data.
-
.decompress(data) ⇒ String
Decompress the data.
Class Method Details
.decode(encrypt_key, encrypted_data) ⇒ String
Decode the data
15 16 17 18 19 20 21 22 |
# File 'lib/khl/webhook.rb', line 15 def self.decode(encrypt_key, encrypted_data) encrypted_data = Base64.strict_decode64(encrypted_data) cipher = OpenSSL::Cipher.new("aes-256-cbc") cipher.decrypt cipher.iv = encrypted_data[0..15] cipher.key = encrypt_key.ljust(32, "\0") cipher.update(encrypted_data) + cipher.final end |
.decompress(data) ⇒ String
Decompress the data
27 28 29 |
# File 'lib/khl/webhook.rb', line 27 def self.decompress(data) Zlib::Inflate.inflate(data) end |