module MournfulSettings::SettingMethods::Cipher

Based on philtoland.com/post/807114394/simple-blowfish-encryption-with-ruby

Public Class Methods

blowfish_cipher() click to toggle source
# File lib/mournful_settings/setting_methods/cipher.rb, line 37
def self.blowfish_cipher
  'bf-cbc' 
end
cipher(mode, data) click to toggle source
# File lib/mournful_settings/setting_methods/cipher.rb, line 6
def self.cipher(mode, data)
  cipher = OpenSSL::Cipher::Cipher.new(config).send(mode)
  cipher.key = Digest::SHA256.digest(key)
  cipher.update(data) << cipher.final
end
config() click to toggle source
# File lib/mournful_settings/setting_methods/cipher.rb, line 33
def self.config
  @config ||= blowfish_cipher
end
config=(text) click to toggle source
# File lib/mournful_settings/setting_methods/cipher.rb, line 28
def self.config=(text)
  raise "'#{text}' is not a value cipher" unless OpenSSL::Cipher::Cipher.ciphers.include?(text)
  @config = text 
end
decrypt(text) click to toggle source
# File lib/mournful_settings/setting_methods/cipher.rb, line 16
def self.decrypt(text)
  cipher(:decrypt, text)
end
encrypt(data) click to toggle source
# File lib/mournful_settings/setting_methods/cipher.rb, line 12
def self.encrypt(data)
  cipher(:encrypt, data)
end
key() click to toggle source
# File lib/mournful_settings/setting_methods/cipher.rb, line 24
def self.key
  @key ||= 'Set your own with Setting::Cipher.key = your_key'
end
key=(text) click to toggle source
# File lib/mournful_settings/setting_methods/cipher.rb, line 20
def self.key=(text)
  @key = text
end