Skip to content

Instantly share code, notes, and snippets.

@misternu
Created December 13, 2018 17:11
Show Gist options
  • Select an option

  • Save misternu/f5d14cc8287a4d22539a338c87214894 to your computer and use it in GitHub Desktop.

Select an option

Save misternu/f5d14cc8287a4d22539a338c87214894 to your computer and use it in GitHub Desktop.
Password Zipping a File
require 'tempfile'
require 'rubygems'
require 'zip'
file = Tempfile.open('testing.txt')
file.write('this is some secret text here')
file.rewind
zipbuffer = Zip::OutputStream.write_buffer(::StringIO.new(''), Zip::TraditionalEncrypter.new('password')) do |out|
out.put_next_entry("testing.txt")
out.write open(file).read
end
encrypted = File.open('encrypted.zip', 'w')
encrypted.write(zipbuffer.string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment