Created
December 13, 2018 17:11
-
-
Save misternu/f5d14cc8287a4d22539a338c87214894 to your computer and use it in GitHub Desktop.
Password Zipping a File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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