3

I'd like to unzip an encrypted/password protected file via a Ruby script without dropping down to a system call. I currently use the rubyzip library to unzip files but don't see an option for working with encrypted files.

Anyone know of some code or a library that will do this?

digitalsanctum
  • 3,261
  • 4
  • 29
  • 43
  • The requirements changed and I don't have to unzip a password protected file anymore so I'm using RubyZip to do the unzip. Thanks for the answers. – digitalsanctum Jun 09 '09 at 18:09

5 Answers5

4

Yes, there is one that works great by the way, I've just tried it and found your post in the middle..

Archive-zip

Example of use:

require 'archive/zip'
Archive::Zip.extract('example5.zip', 'a_destination', :password => 'seakrit')

I'm sure that this will be useful for someone else looking for the same on google :)

kainlite
  • 1,024
  • 17
  • 35
  • 1
    Your answer was useful for somebody searching via google ;) Can be installed via `gem install archive-zip` and worked without problem. – knut Jan 03 '14 at 22:15
2

Sometimes the right answer is to use a system call. That's why it's there.

True, it's slower and less elegant than using a library or a method. But it's cheaper than paying a tax to someone (a royalty payment) and much much faster than writing a new library yourself.

Larry K
  • 47,808
  • 15
  • 87
  • 140
1

The only one I've heard of to date is the Chilkat Ruby Zip library, which isn't free. The RubyZip library does not support password-protected files because the underlying library, zlib, doesn't do so either.

John Feminella
  • 303,634
  • 46
  • 339
  • 357
  • RubyZip supports password protected unzip: https://github.com/rubyzip/rubyzip/blob/e5e3f97ec891cb596f1af8950fc9749c99b809e9/test/encryption_test.rb – diman Jan 20 '21 at 13:18
0

Not a ruby library, but...maybe a free option.

If your app runs on Windows, you can use the DotNetZip library, via the new COM interface. It does password-protected files, either Zip encryption (weak), or WinZip-compatible AES encryption.

DotNetZip is free.

If Windows is out of the question, there may be another possibility. DotNetZip runs in Mono, too. I don't know if there are Ruby-to-Mono integration mechanisms to allow you to call from Ruby to Mono on other platforms, but if they exist, they also may let you call into DotNetZip.

Cheeso
  • 189,189
  • 101
  • 473
  • 713
0

There's always the option of using JRuby + a Java library for handling zip files. http://www.lingala.net/zip4j handles (encrypted) zip files and is Apache licensed. I've not used it yet, but it should work.

Craig C.
  • 161
  • 2
  • 5