Module: Secret::Encryption

Defined in:
lib/secret/encryption.rb

Instance Method Summary collapse

Instance Method Details

#contentsObject



34
# File 'lib/secret/encryption.rb', line 34

def contents; raise "Not Implemented"; end

#encrypt_basic(passphrase) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/secret/encryption.rb', line 8

def encrypt_basic(passphrase)
  cipher = OpenSSL::Cipher.new('aes-256-cbc')
  cipher.encrypt
  key = passphrase
  iv  = cipher.random_iv

  out = StringIO.new("", "wb") do |outf|
    StringIO.new(contents, "rb") do |inf|
      while inf.read(4096, buf)
        outf << cipher.update(buf)
      end
      outf << cipher.final
    end
  end

  return out.string
end

#encrypted?Boolean

Checks to see if the file is encrypted

Returns:

  • (Boolean)


27
28
29
# File 'lib/secret/encryption.rb', line 27

def encrypted?
  ::File.exist?(encrypted_meta_filename)
end

#stash(content) ⇒ Object



32
# File 'lib/secret/encryption.rb', line 32

def stash(content); raise "Not Implemented"; end