module Encryption::String

Public Instance Methods

decrypt(options = {}) click to toggle source
# File lib/helpers/string.rb, line 12
def decrypt(options = {})
  string = self
  string = Base64.decode64(self) if options[:encode] or options[:encoded]
  encryptor(options).decrypt string
end
decrypt!(options = {}) click to toggle source
# File lib/helpers/string.rb, line 22
def decrypt!(options = {})
  replace decrypt(options)
end
encrypt(options = {}) click to toggle source
# File lib/helpers/string.rb, line 6
def encrypt(options = {})
  string = encryptor(options).encrypt self
  string = Base64.encode64(string) if options[:encode]
  string
end
encrypt!(options = {}) click to toggle source
# File lib/helpers/string.rb, line 18
def encrypt!(options = {})
  replace encrypt(options)
end

Private Instance Methods

encryptor(options) click to toggle source
# File lib/helpers/string.rb, line 28
def encryptor(options)
  return Encryption if options.empty?
  return options[:encryptor] if ! options[:encryptor].nil?

  encrypt = Encryption::Symmetric.new

  options.each do |key, value|
    encrypt.send(key.to_s + '=', value) if encrypt.respond_to? key.to_s + '='
  end

  encrypt
end