Skip to content

Instantly share code, notes, and snippets.

@cmrd-senya
Created February 29, 2016 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmrd-senya/2b6a9ac69f05b0285bbe to your computer and use it in GitHub Desktop.
Save cmrd-senya/2b6a9ac69f05b0285bbe to your computer and use it in GitHub Desktop.
require "openssl"
ARCHIVE_MAGIC = "D*ARCHIVE"
if ARGV[0].nil?
puts "Usage: #{__FILE__} <encrypted archive>"
exit 1
end
File.open(ARGV[0], "rb") do |f|
if f.read(9) != ARCHIVE_MAGIC
puts "Bad magic"
exit 2
end
STDERR.puts "Enter password:"
password = STDIN.readline.rstrip
salt = f.read(16)
iv = f.read(16)
key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(password, salt, 20000, 32)
cipher = OpenSSL::Cipher::AES256.new(:CBC).decrypt
cipher.key = key
cipher.iv = iv
File.open("/tmp/out.json.gz", "wb") do |o|
o.write(cipher.update(f.read) + cipher.final)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment