module NmDatafile::FileEncoding
Public Instance Methods
deobfuscate_file_format()
click to toggle source
# File lib/nm_datafile/file_encoding.rb, line 69 def deobfuscate_file_format end
encode_datafiles_as_zip(hash_of_entries)
click to toggle source
hash consists of {file1: string_data} output is a binary string representing a zip file of the entries specified
# File lib/nm_datafile/file_encoding.rb, line 11 def encode_datafiles_as_zip(hash_of_entries) temp_file = Tempfile.new(file_type.to_s, get_temp_directory) FileUtils.rm temp_file.path stream = ::Zip::OutputStream.write_buffer do |zos| hash_of_entries.each do |entry_name, data| zos.put_next_entry entry_name zos.write data end end stream.rewind stream.read end
encode_string_as_password_protected(encryptable_portion, pass = nil)
click to toggle source
TODu: rename to encode_password_protected_string
# File lib/nm_datafile/file_encoding.rb, line 55 def encode_string_as_password_protected(encryptable_portion, pass = nil) pish = @password pish = pass unless pass.nil? raise "error, password given was too long, must be 56 or less chars" if pish.length > 56 encrypted = Blowfish.encrypt(pish, encryptable_portion) encrypted end
encode_string_as_password_protected_old_zip_based(encryptable_portion, pass = nil)
click to toggle source
Play: Below will write to stdout as long as stdout isn’t the terminal (so works in irb and ruby) zip -P ‘fp5!IZbVxgx2hWh8m*UQyc@d5nCGCrbiqPx73hh&’ - file_to_add
Below is attempt to read file from stdin: out = ‘echo ’hi’ | zip -P ‘fp5!IZbVxgx2hWh8m*UQyc@d5nCGCrbiqPx73hh&’ - -‘
Zip commandline is zip -P ‘fp5!IZbVxgx2hWh8m*UQyc@d5nCGCrbiqPx73hh&’ zip_to_make.zip file_to_add maybe password has invalid chars
# File lib/nm_datafile/file_encoding.rb, line 37 def encode_string_as_password_protected_old_zip_based(encryptable_portion, pass = nil) pish = @password pish = pass unless pass.nil? supress_errors = "2>/dev/null" # this will read that file... let's try passing it in from stdin pipes though # alt = "zip -P '#{pish}' - #{@@clear_text_path}" # TODu: escape single quotes or this command breaks... raise "tried to encrypt an encryptable_portion which contained illegal character ' which would break the command being piped to zip" if encryptable_portion =~ /\'/ # passing in clear_text through pipes alt = "echo '#{encryptable_portion}'| zip -P '#{pish}' - - #{supress_errors}" #alt = "echo '#{encryptable_portion.gsub("\\n", "")}'| zip -P '#{pish}' - -" binary_output = `#{alt}` end
obfuscate_file_format()
click to toggle source
# File lib/nm_datafile/file_encoding.rb, line 65 def obfuscate_file_format # TODu: implement me end