class ResponseEncryption::AsymmetricEncrypter
Attributes
encrypted_data[R]
public_key[R]
Public Class Methods
new(options={})
click to toggle source
# File lib/response_encryption/asymmetric_encrypter.rb, line 5 def initialize(options={}) validate(options) @public_key = OpenSSL::PKey::RSA.new(options[:public_key]) end
Public Instance Methods
encrypt(data, encode_data = true)
click to toggle source
@param data [ Object
] which should respond to to_s @param encode_data [ Boolean ] @return [ String ] with the encrypted and encoded information
# File lib/response_encryption/asymmetric_encrypter.rb, line 13 def encrypt(data, encode_data = true) return data if data.blank? encrypted = public_key.public_encrypt(data.to_s) @encrypted_data = encode_data ? Base64.encode64(encrypted) : encrypted end
validate(options)
click to toggle source
# File lib/response_encryption/asymmetric_encrypter.rb, line 19 def validate(options) errors.add(:param_missing, 'You must to provide public_key option') if options[:public_key].blank? end