Module: MournfulSettings::Setting::Cipher

Defined in:
lib/mournful_settings/setting/cipher.rb

Overview

Class Method Summary collapse

Class Method Details

.blowfish_cipherObject



37
38
39
# File 'lib/mournful_settings/setting/cipher.rb', line 37

def self.blowfish_cipher
  'bf-cbc' 
end

.cipher(mode, data) ⇒ Object



6
7
8
9
10
# File 'lib/mournful_settings/setting/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

.configObject



33
34
35
# File 'lib/mournful_settings/setting/cipher.rb', line 33

def self.config
  @config ||= blowfish_cipher
end

.config=(text) ⇒ Object



28
29
30
31
# File 'lib/mournful_settings/setting/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) ⇒ Object



16
17
18
# File 'lib/mournful_settings/setting/cipher.rb', line 16

def self.decrypt(text)
  cipher(:decrypt, text)
end

.encrypt(data) ⇒ Object



12
13
14
# File 'lib/mournful_settings/setting/cipher.rb', line 12

def self.encrypt(data)
  cipher(:encrypt, data)
end

.keyObject



24
25
26
# File 'lib/mournful_settings/setting/cipher.rb', line 24

def self.key
  @key ||= 'Set your own with Setting::Cipher.key = your_key'
end

.key=(text) ⇒ Object



20
21
22
# File 'lib/mournful_settings/setting/cipher.rb', line 20

def self.key=(text)
  @key = text
end