Is it possible to encrypt a Zip file? I know encryption is used to make .txt files unreadable until decrypted with a key. Although I want to do the same with a .zip file.
I have multiple files I want users to download from the internet through my program I'm creating, so I thought I'll compress them files in a .zip and then encrypt the Zip for added security. (I don't want users to access the file within the .zip without a serial code)
I was going to keep the 'serial key' in a database online which the program would get.
Am going about this in the wrong way?
Both DotNetZip and SharpZipLib support encrypting the contents of zips and are free.
Use the dotnetzip library to perform your zipping/unzipping operations.
It supports AES encryption. From the website:
The library supports zip passwords, Unicode, ZIP64, stream input and output, AES encryption, multiple compression levels, self-extracting archives, spanned archives, and more.
Yes you can use third party zip libraries as shown by other answers, but keep in mind that your method of protecting files is rudimentary... it would not be terribly difficult to observe your program operating and recover the files after your program helpfully decrypts them. If you are storing the key as a constant in the program, that is pretty trivial to extract as well.
Software protection is a complex field, and it's very difficult to prevent determined users from viewing data that is stored on systems they control. Commercial software goes to great lengths to prevent this, and the solutions are quite complicated. (e.g. try hooking a debugger to Skype and see what happens)
Related
Context:
To save more space, I want to further compress some files in a zip archive with an algorithm, and other files in same archive with another algorithm. Later I need to revert the process to get the original zip archive, because the zip files are owned by users.
How to locate compressed bits of certain files in a zip archive for further processing?
Language: Guess this kind of code is usually C/C++ for performance, but C# is good too.
OS: Windows Server 2012 R2 or later.
Edit:
I learned that in zip(zlib) format, compressed files are organized in blocks. We should be able to locate the files by searching headers. Still checking on how to code it.
The zip file format is fully documented. e.g. http://www.fileformat.info/format/zip/corion.htm
You can find other sources and descriptions easily.
What you have to do is to read bytes according to the format and you have exact knowledge about where a certain file's compressed bits are. You can find open source libraries for this or you can roll your own in your preferred language.
As a side note, compressing an otherwise compressed file in a zip archive may not worth the efforts.
I have a folder with music videos which I want to backup from my laptop to a external hdd. I dont want to use a backup-Image, but a direct file copy so I can directly watch the music videos from the backup hdd on another computer/laptop or a console.
Curently I use the freeware SyncBack Free to mirror the files to the external hdd. SyncBack Free is a nice tool, but it does not seem to fully satisfy my needs. The problem is that I like to modify the filenames of my music videos from time to time. Though SyncBack Free has a option for files with identical content it does not seem to work for videos and you end up with two copies from the same file in each folder when you synchronise after a file name change.
So im thinking about writing my own freeware backup software.
The question is:
-how can I identify identical files with c#/.Net 4.0 without using the filename? Im thinking of generating hashes or a checksum for the files without knowing much about it
-Is it to slow to really be used for a backup software?
You can get a hash of a file like this
using System.Security.Cryptography;
static string GetFileHash(string filename)
{
byte[] data = File.ReadAllBytes(filename);
byte[] hash = MD5.Create().ComputeHash(data);
return Convert.ToBase64String(hash);
}
MD5 is not the most secure hash, but it is still fast which makes it good for file checksums. If the files are large ComputerHash() also takes a Stream.
You may also want to check out some other check sum algorithms in the HashLib library. It contains CRC and other algorithms which should be even faster. You can download it with nuget.
There are other strategies you can use as well such as checking if only the first x bytes are the same.
You can keep a database of hashes that have been backed up so that you don't have to recompute the hashes each time the backup runs. You could loop through only files which have been modified since the last backup time and see if their hash is in your hash database. SQLite comes to mind as a good database to use for this if you want your backup program to be portable.
With a backup application, a good and space-efficient way to back up is to detect changes in files. Some online services such as Dropbox do this as well since Dropbox includes version history. How do backup applications detect changes in files and store them?
If you have a monumentally large file which has already been backed up, and you make a small change (such as in a Microsoft Word document), how can an application detect a change and process it? If the file has changes made often, there must be an efficient algorithm to only process changes and not the entire file. Is there an algorithm to do this in C# .NET?
Edit: I'm trying to figure out how to encode two files as the original and the changes (in a VCDIFF format or etc.) I know how to use the format and decode it just fine.
to detect changes, you can compute the Hash code (such as MD5) for the original and the modified versions of the file. if they are identical, no changes are made.
I think DropBox has its own protocol to detect which part of this file is modified.
you can figure out to find out your own way, for example, divide the file to fixed-size parts, store their hash codes. when the client download the file, send these information to the client. after modifying the file, recalculate the hash codes for the parts, compare them with original hash codes, upload the parts that were modified, rebuild the file from original parts and the modified parts.
rsync is an open source tool that synchronizes files using delta encoding.
----------------------------------------------------EDIT: my idea above is very simple and not efficient. you can a look at VCDIFF that were explained by research paper and implemented in many languages (C#).
So, we will be given mkv files that are to be sent to multiple client sites. We need to encrypt the contents of those files prior to transmission, but in a way that the client can begin to playback those files, decrypting them on the fly. We know we can simply encrypt the file itself, but then the client would have to decrypt it prior to playback, leaving the unencrypted file open for pilfering. Have been googling for encrypt mkv but have not yet turned up anything. Is this possible to do? A library to accomplish this (Windows encryption side, Linux playback side) would be ideal but a cross-platform app would suffice in a pinch.
Stream-layer encryption is certainly supported in Matroska (as opposed to what Adam says):
See:
http://matroska.org/technical/specs/notes.html#Encryption
You need to bring the encryption yourself, however. Most likely the way that jbtule proposes will work. Could you report back to us? I'm looking into encrypting some MKV's myself.
There aren't standard DRMs. But you can use standard crypto, You don't want to encrypted the entire file, just the video stream inside the container with a stream cipher, thus you can hook in at the parser level in whatever opensource MKV library you are using to then decrypt the chunk of the stream before it passes it to the codec. You'll want a choose a standard stream cipher that is fast and will let you skip to later places in the stream (e.g. Salsa20)
This is not possible; as a container format, the Matroska (MKV) format does not support DRM. You'll need to use something like ASF, which is the container format most often used by WMV, or QuickTime.
The subject of how to develop for DRM is far too broad to cover here. You'll need to select what DRM system you want to use and license it. This is non-trivial.
You might start here. Note that, as with most DRM schemes, the only people that you will inconvenience will be your paying customers. If someone wants your content, they will get it.
I currently have an app written in C# that can take a file and encrypt
it using gpg.exe
What I'm trying to do is, instead of
1. Creating a file (from database queries usually)
2. encrypting the file
3. deleting the non-encrypted file
I want to
Gather info into memory (into a dictionary or a list or whatever)
stream the text/data into gpg.exe to end up with the encrypted file
outputted
I've looked into pipestream, redirecting standard input to the gpg
process, etc, but I haven't figured out a way to trick gpg.exe into
accepting streamed text/data instead of a file on the hard drive.
Initially figured if I could do it for gpg, I could also do it for Zip
as well, but I'm wondering if it's even possible.
Found some refs to popen which seems to be php related, but nothing
for c#.
Essentially, I'm looking to do the below programatically with text.txt
being stuff in memory streamed to the app instead of an actual file on
the hard drive.
C:\Program Files\GNU\GnuPG>type C:\test.txt | zip > plubber.zip
C:\Program Files\GNU\GnuPG>type C:\test.txt | gpg -er
"mycomp_operations " > Test.pgp
Thanks for any help you may be able to give :)
Tony!
You can use DotNetZip to create a zip file in-memory, but I don't know how that would interface with the gpg stuff. DotNetZip can do AES encryption, but that is obviously a different model from PGP or GPG.
Just a quick googly search turned up
this hint on GPG.
Looks like they run the gpg.exe in a separate process, sitting there waiting for input.
Please review the BouncyCastle C# implementation at:
http://www.bouncycastle.org/csharp/
This will allow GPG inprocess encryption and decryption without external files. I am currently using it to do the same thing for a BizTalk pipeline component.
Benton Stark has written a good wrapper for GnuPG which demonstrates (among other things) how to take data from a Stream, pipe it into the GPG executable and write the output back to a stream - all in C#.
Benton has answered another question with a link to his website. Benton writes:
You can try using my open source and free GnuPG wrapper for C# (and
VB.NET). All the code is licensed via MIT, non-GPL restrictions. You
can find the release with source code on Sourceforge.net.
http://sourceforge.net/projects/starksoftopenpg/
Well, named-pipes does most of what you are discussing, but to be honest it isn't worth it... in most cases, a temp file is a reasonable approach.
Using our SecureBlackbox components you can avoid calling external program for ZIP or PGP operations. The components operate with streams and don't need temporary files.