Sha256: 566270a425ba596664681674a54f95f6b25f7ce59fcbdfaaac0d88d51009d52f
Contents?: true
Size: 1.26 KB
Versions: 4
Compression:
Stored size: 1.26 KB
Contents
require 'openssl' require 'base64' module Eligible class Lockbox < APIResource def self.get(params, opts = {}) send_request :get, api_url('lockboxes', params, :lockbox_id), params, **opts.merge(required_params: [:lockbox_id]) end def self.all(params, opts = {}) send_request :get, api_url('lockboxes'), params, **opts end def self.extract_private_key(params) private_key = Util.value(params, :private_key) fail ArgumentError, "Private key is required for decryption" if private_key.nil? private_key end def self.delete_private_key!(params) params.delete('private_key') params.delete(:private_key) end def self.decrypt_data(data, encrypted_data_key, private_key) pkey = OpenSSL::PKey::RSA.new(private_key) aes_key = pkey.private_decrypt(Base64.decode64(encrypted_data_key)) sha_key = Digest::SHA256.hexdigest(aes_key) Encryptor.decrypt(value: Base64.decode64(data), key: sha_key, insecure_mode: true) end def self.get_and_decrypt_from_lockbox(params, opts = {}) private_key = extract_private_key(params) delete_private_key!(params) req = get(params, **opts).to_hash decrypt_data(req[:encrypted_data], req[:encrypted_key], private_key) end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
eligible-3.1.0.beta4 | lib/eligible/lockbox.rb |
eligible-3.1.0.beta3 | lib/eligible/lockbox.rb |
eligible-3.1.0.beta2 | lib/eligible/lockbox.rb |
eligible-3.1.0.beta1 | lib/eligible/lockbox.rb |