class MailDaemon::Encryption

Public Class Methods

new() click to toggle source
# File lib/mail_daemon/encryption.rb, line 6
def initialize()
  @key = ENV["CASEBLOCKS_ENCRYPTION_KEY"] || "YLX0IBT+OXaO4mP2bVYqzMPbrrss8eUcX1XtgLxlVH8="
  @iv = ENV["CASEBLOCKS_ENCRYPTION_IV"] || "vvSVfoWvZQ3T/DfjsjO/9w=="
end

Public Instance Methods

decrypt(value) click to toggle source
# File lib/mail_daemon/encryption.rb, line 26
def decrypt(value)
  unless value.nil?
    decipher = OpenSSL::Cipher::AES.new(128, :CBC)
    decipher.decrypt
    decipher.key = Base64.decode64(@key)
    decipher.iv = Base64.decode64(@iv)

    encrypted = Base64.decode64(value)
    decipher.update(encrypted) + decipher.final
  else
    value
  end
end
encrypt(data) click to toggle source
# File lib/mail_daemon/encryption.rb, line 11
def encrypt(data)
  unless data.nil?
    cipher = OpenSSL::Cipher::AES.new(128, :CBC)
    cipher.encrypt
    cipher.key = Base64.decode64(@key)
    cipher.iv = Base64.decode64(@iv)
    encrypted = cipher.update(data) + cipher.final

    # [0..-2] strip off trailing carriage return
    Base64.encode64(encrypted)[0..-2]
  else
    data
  end
end