Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.