Skip to content

Instantly share code, notes, and snippets.

@nviennot
Created March 28, 2014 01:32
Show Gist options
  • Save nviennot/9823207 to your computer and use it in GitHub Desktop.
Save nviennot/9823207 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'openssl'
require 'tempfile'
# How to use:
# cd assets/data
# find . -type f -print0 | xargs -L1 -0 ./decrypt.rb
input_path = ARGV[0]
cipher = OpenSSL::Cipher::AES256.new(:CBC)
cipher.key = "USCaPQpA4TSNVxMI1v9SK9UC0yZuAnb2"
out = ""
begin
out = cipher.update(File.read(input_path)) + cipher.final
rescue OpenSSL::Cipher::CipherError
end
if out[0..3] == "7z\xBC\xAF"
file_7z = Tempfile.new('rv')
begin
file_7z.print out
file_7z.flush
decompressed_data = `7z e -so #{file_7z.path}`
File.write(input_path, decompressed_data)
ensure
file_7z.close
file_7z.unlink
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment