Created
February 29, 2016 14:49
-
-
Save cmrd-senya/2b6a9ac69f05b0285bbe to your computer and use it in GitHub Desktop.
This file contains 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 "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