Sha256: 2f079a59c98266cfd3812112274fc67552c65d12d11409044150f501f5774c3b

Contents?: true

Size: 889 Bytes

Versions: 13

Compression:

Stored size: 889 Bytes

Contents

require 'openssl'

module Heirloom
  module Cipher
    class Data

      def initialize(args)
        @config = args[:config]
        @logger = @config.logger
      end

      def decrypt_data(args)
        data   = args[:data]
        secret = args[:secret]

        return data unless args[:secret]

        @logger.info "Secret provided. Decrypting archive."

        @aes = OpenSSL::Cipher::AES256.new(:CBC)
        @aes.decrypt
        @aes.key = Digest::SHA256.hexdigest secret
        @aes.iv = data.slice!(0,16)
        begin
          @aes.update(data) + @aes.final
        rescue OpenSSL::Cipher::CipherError => e
          if e.message == 'wrong final block length'
            @logger.error 'This archive does not appear to be encrypted.'
          end
          @logger.error "Unable to decrypt archive: '#{e.message}'"
          false
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
heirloom-0.7.4 lib/heirloom/cipher/data.rb
heirloom-0.7.3 lib/heirloom/cipher/data.rb
heirloom-0.7.3rc2 lib/heirloom/cipher/data.rb
heirloom-0.7.3rc1 lib/heirloom/cipher/data.rb
heirloom-0.7.2 lib/heirloom/cipher/data.rb
heirloom-0.7.2rc2 lib/heirloom/cipher/data.rb
heirloom-0.7.2rc1 lib/heirloom/cipher/data.rb
heirloom-0.7.1 lib/heirloom/cipher/data.rb
heirloom-0.7.0 lib/heirloom/cipher/data.rb
heirloom-0.7.0rc1 lib/heirloom/cipher/data.rb
heirloom-0.6.1 lib/heirloom/cipher/data.rb
heirloom-0.6.0rc1 lib/heirloom/cipher/data.rb
heirloom-0.5.0rc4 lib/heirloom/cipher/data.rb