Sha256: 735608233a72528e7c7e1f77c6511fb4f298f74142db6b1308b2704b0cc862fd

Contents?: true

Size: 1.74 KB

Versions: 24

Compression:

Stored size: 1.74 KB

Contents

# encoding: utf-8

module Backup
  module Encryptor
    class OpenSSL < Base

      ##
      # The password that'll be used to encrypt the backup. This
      # password will be required to decrypt the backup later on.
      attr_accessor :password

      ##
      # Determines whether the 'base64' should be used or not
      attr_writer :base64

      ##
      # Determines whether the 'salt' flag should be used
      attr_writer :salt

      ##
      # Creates a new instance of Backup::Encryptor::OpenSSL and
      # sets the password attribute to what was provided
      def initialize(&block)
        load_defaults!

        @base64 ||= false
        @salt   ||= false

        instance_eval(&block) if block_given?
      end

      ##
      # Performs the encryption of the backup file
      def perform!
        log!
        run("#{ utility(:openssl) } #{ options } -in '#{ Backup::Model.file }' -out '#{ Backup::Model.file }.enc' -k '#{ password }'")
        rm(Backup::Model.file)
        Backup::Model.extension += '.enc'
      end

    private

      ##
      # Backup::Encryptor::OpenSSL uses the 256bit AES encryption cipher.
      # 256bit AES is what the US Government uses to encrypt information at the "Top Secret" level.
      def options
        (['aes-256-cbc'] + base64 + salt).join("\s")
      end

      ##
      # Returns '-a' if @base64 is set to 'true'.
      # This option will make the encrypted output base64 encoded,
      # this makes the encrypted file readable using text editors
      def base64
        return ['-base64'] if @base64; []
      end

      ##
      # Returns '-salt' if @salt is set to 'true'.
      # This options adds strength to the encryption
      def salt
        return ['-salt'] if @salt; []
      end

    end
  end
end

Version data entries

24 entries across 24 versions & 3 rubygems

Version Path
backup-3.0.19 lib/backup/encryptor/open_ssl.rb
backup-3.0.18 lib/backup/encryptor/open_ssl.rb
interu-backup-3.0.16 lib/backup/encryptor/open_ssl.rb
backup-3.0.16 lib/backup/encryptor/open_ssl.rb
backup-3.0.15 lib/backup/encryptor/open_ssl.rb
backup-3.0.14 lib/backup/encryptor/open_ssl.rb
backup-3.0.13 lib/backup/encryptor/open_ssl.rb
backup-3.0.12 lib/backup/encryptor/open_ssl.rb
backup-3.0.11 lib/backup/encryptor/open_ssl.rb
alg-backup-3.0.10 lib/backup/encryptor/open_ssl.rb
backup-3.0.10 lib/backup/encryptor/open_ssl.rb
backup-3.0.9 lib/backup/encryptor/open_ssl.rb
backup-3.0.8 lib/backup/encryptor/open_ssl.rb
backup-3.0.7 lib/backup/encryptor/open_ssl.rb
backup-3.0.6 lib/backup/encryptor/open_ssl.rb
backup-3.0.5 lib/backup/encryptor/open_ssl.rb
backup-3.0.4 lib/backup/encryptor/open_ssl.rb
backup-3.0.3 lib/backup/encryptor/open_ssl.rb
backup-3.0.2.build.0 lib/backup/encryptor/open_ssl.rb
backup-3.0.2 lib/backup/encryptor/open_ssl.rb