We have stored image as an encrypted format and stored in local path. And once we captured the all documents the user click on submit button on that scenario we have decrypted all the images using RNCryptor(https://github.com/RNCryptor/RNCryptor) and save as Zip and https://github.com/marmelroy/Zip
But we have to store a decrypt format in memory instead of disk.
How would I zip a file so I could send it without writing to the hard drive and do it purely in memory?
Update
Another alternative is the ZIPFoundation library on Github (MIT/Thomas Zoechling). It appears to be Swift compatible and is apparently "effortless." BTW - I learned about this library while reading an interesting blog article where the author (Max Desiatov) walks through how he unzips in memory using the library (see the section - Unzipping an archive in memory and parsing the contents).
Original
Have you taken a close look at the Single-Step Compression article? There is a section that talks about writing the compressed data to file (but it's already been compressed in memory at that point). Once you get the data generated then I guess you could do with it as you will...
Article Steps
Create the Source Data
Create the Destination Buffer
Select a Compression Algorithm
Compress the Data
Write the Encoded Data to a File
Read the Encoded Data from a File
Decompress the Data
Related
I'm trying to read and analysis iPhone backup files in Library/Application Support/MobileSync/Backup folder.
I use SQLite DB viewer to view the manifest.db:
Files TABLE structure
Files TABLE content
The filename is encrypted. And the file is blob type which I can't decide it's an image or text or documents.
How can I get the details of these backup? (Using Javascript would be best, or Swift).
The numbers and letters under fileID are the file names in the backup as in the folders with the manifest.db, and they correspond to the domain and relative path (duh). In iOS versions newer than 9.3.5, you can find the file itself in the folder named with the 1st 2 characters of the fileID. At the end of the relative path in the database it should have an extension. Use that as a hint to what program to use to open the file. Xcode for .plist etc. Ultimately it depends what you're looking for...
The blob in the blob column is a binary plist. You can parse it using a plist parser e.g. Property List Parsing
The blob appears to be base64 encoded, but I cannot figure out the type of the resulting binary blob. I've checked to see if it can be decrypted with openssl enc -aes-256-cbc -d decoded-string-as-binary-blob.datafile but I get back "bad magic." I've also tries all of the other AES encryption ciphers and block cipher modes, but no change. It could always be XOR'd with a value, but I haven't found an easy to test that theory.
I am hosting a small fileserver, where users can upload documents from all around the world.
Due to problems in encoding (see otherquestion), I am asking myself if I should disallow users to upload (and on the other hand download) files not supported by CP1252 charset?
or otherwise; is it senseful to allow users upload documents with arabian or chinese letters in their filenames?
PS: they download the same file some time later (and it should have the same filename as uploaded)
You should be storing the files on disk using a randomly generated name, or let the file name be based on a hash of the file contents (good for deduplicating storage as well). You can save the original file name as meta data in a database together with all other meta data about the file (who uploaded it and things like that). Then you serve the file again using a PHP script which sets the original file name from the database in an HTTP header. This way you:
don't need to worry about file name sanitisation or duplication
file system encoding issues
storage duplication (if using a hash)
I have a sqlite file(it may be either encrypted or non-encrypted) in Document Directory in an already created app, now in updated version i have to check it for decryption, if file is found encrypted then we will use it after decryption but it found non-encrypted then we will use it simply.
Is there any way to do it?
According to "The SQLite Database File Format",
every SQLite file starts with the bytes "SQLite format 3", followed by a nul termination.
Assuming that the encryption scrambles all bytes of the file, you can read the first 16
bytes and check if they match the above string.
But a simpler method is to just open the file with sqlite3_open() or one of the
related open calls. If that fails with the error code SQLITE_CORRUPT, you can assume
that the file was encrypted, so you decrypt it and open it again.
If you know what the encryption method is beforehand, you can try to find fingerprints of the method in order to detect if the file is encrypted or not. But there are encryption methods that are designed specifically to hide encryption into files that do not look encrypted.
This is the case of watermarking encryption embedded into images. You can open the images and they will look like any ordinary image file, but in fact there is encrypted information there.
I'm developing a download manager using Indy and Delphi XE (The application uses Multithreading to attempt several connections to the server). Everything works fine but sometimes the final downloaded file is broken and when I check downloaded temp files I see that 2 or 3 of them is filled with zero at their end. (Each temp file is download result of each connection).
The larger the file is, the more broken temp files I get as the result.
For example in one of the temp files which was 65,536,000 bytes, only the range of 0-34,359,426 was valid and from 34,359,427 to 64,535,999 it was full of zeros. If I delete those zeros, application will automatically download the missing segments and what I get as the result, well if the problem wouldn't happen again, is the healthy downloaded file.
I want to get rid of those zeros at the end of the temp files without having a lost in download speed.
P.S. I'm using TFileStream and I'm sending it directly to TIdHTTP and downloading the files using GET method.
Additional Info: I handle OnWork event which assigns AWorkCount to a public int64 variable. Each time the file is downloaded, the downloaded file size (That Int64 variable) is logged to a text file and from what the log says is that the file has been downloaded completely (even those zero bytes).
Make sure the server actually supports downloading byte ranges before you request a range to download. If the server does not support ranges, a requested range will be ignored by the server and the entire file will be sent instead. If you are not already doing so, you should be using TIdHTTP.Head() to text for range support before then calling TIdHTTP.Get(). You also need to do this anyway to detect if the remote file has been altered since the last time you downloaded it. Any decent download manager needs to be able to handle things like that.
Also keep in mind that if TIdHTTP knows up front how many bytes are being transferred, it will pre-allocate the size of the destination TStream before then downloading data into it. This is to speed up the transfer and optimize disc I/O when using a TFileStream. So you should NOT use TFileStream to access the same file as the destination for multiple simultaneous downloads, even if they are writing to different areas of the file. Pre-allocating multiple TFileStream objects will likely trample over each other trying to set the file size to different positions. If you need to download a file in multiple pieces simultaneously then either:
1) download each piece to a separate file and copy them into the final file as needed once you have all of the pieces that you need.
2) use a custom TStream class, or Indy's TIdEventStream class, to manage the file I/O yourself so you can ignore TIdHTTP's pre-allocation attempts and ensure that multiple file I/O operatons do not overlap each other incorrectly.
I have an app that uses copyrighted images that I have permission to use. If a user downloads my app onto their computer using iTunes, they can basically unzip the app file (change filename to add .zip, unzip then show package contents), and see the images.
Is there a way to prevent this? Or am I wrong about this?
To the best of my knowledge there is no way to stop this method of accessing the images; the only alternative I can think of is to encrypt the images and store the encrypted files in the app. Then decrypt the images at runtime.
This won't stop the most determined adversary but would stop people accessing the images without some effort on their part.
A determined adversary will likely be able to get at any files used by an app on a device in their possession.
To defeat a lazy adversary, you might only have to change the file names into something they won't recognize as an image file. Or change a few bytes containing the file type signature at the beginning of each file, rendering the file corrupt. Your app can copy them into a temp file and fix the signatures to display.
Apple reportedly encrypts an App store distributed app's compiled C code. So another possibility might be to embed (portions of) the copyrighted images as hex data inside your source code.