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.
Related
This is a bit of a weird question but, with the functionalities of C++, c# and objective C as we speak is there any possible way for video content to be uploaded whilst its recording. So as you record the video it would be being compressed and uploaded to a website.
Would this involve cutting the video into small parts as you record, hardly noticeable stops and starts during the recording?
If anyone knows if this is at all possible, please let me know.
Sorry for the odd question.
You've just asked for streaming media -- something that's been done for over a decade (and, if you overlook "television", something that's probably been underway in research settings for several decades).
Typically, the video recorder will feed the raw data through filters of some sort -- correct white balance, sharpen or soften the video, image stabilize, and then compress the raw data using a codec. Most codec designs will happily take a block of input, work on it, and then produce a block of encoded data ready for writing. Instead of writing to disk, you could "write" to a socket opened to a remote machine.
Or, if you're working with an API that only writes to disk, you could easily re-read the data off disk as it is being written and send the data to a remote site. You'd have to "follow" the writing using something like tail -f's magic ability to follow the file as it is written. (Heck, if you're just bodging something together for a one-off, I'd even recommend using tail -f as part of your system.)
It depends on if the application recording to disk is locking the file. My guess is that, unless you wrote the recording software, the application locks the file(or doesn't even create the real file) until it stops recording. If you are writing the recording software as well, then yes, you can do this. you would just use sychronized threads.
Say you have a method or property on a third party sealed component that expects a file name. You do not have the source for the third party component. You want that component to do what it's supposed to do (read only) on a file you have, but your file is encrypted on disk and you only want the decrypted version in memory so it cannot be easily copied in its plain form.
Is it possible to create a wrapper or some other approach to trick the component to think it's reading from a file when it's actually reading from a MemoryStream? Or is it totally impossible? Can it be done outside .NET in native Windows code?
Thanks
You can't do that the way that you are proposing, no. My recommendation would be to use the Encrypting Filesystem functionality built into windows. That way the file is stored in encrypted form on disk, but is available via the normal IO methods to the application (provided that the account that is running the application has access to the file).
Can it read from "CON" as input (like many text utilities grep/findstr, more,...)? In this case you can try to redirect input/output stream and feed results thata way.
Is it possible to create a wrapper or some other approach to trick the
component to think it's reading from a file when it's actually reading
from a MemoryStream?
No, sorry. You will have to decrypt the file into a temporary file and then pass this temporary file to the plugin. Once it finishes its work delete the temporary file.
This short answer is if a component is expecting a filename e.g. a string you can not parse it a memory stream.
However if the file is encrypted with Encrypting File System (EFS) or something native to Windows it may be able to decrypt the file without knowing the file is encrypted.
These might help:
http://en.wikipedia.org/wiki/Encrypting_File_System
http://en.wikipedia.org/wiki/BitLocker_Drive_Encryption
You could have a look at Dokan. I haven't tried it, but it's a way of creating a virtual file system in .Net.
You can create an in-memory disk drive (either in code or by using third-party application) and put a file there. Another approach is to implement virtual file system and handle all file requests. Both approaches are possible for example using our Virtual Storage products.
Also, I don't know about .NET in particular, but in Windows you can hook API functions and substitute certain operations (including file operations). There even exist components for this, but, again, I don't know if they offer their functionality for .NET.
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)
I want to make a program that takes an MP3 file and breaks it into many smaller mp3 files based on 1-2 seconds of no sound (silence).
What is the easiest way to do this in c#?
Bass library. Bass has everything you need. It can access, record and edit media streams like mp3s, allowing you to sample the volume at different time points. It has a .net api, so you can use it in c#. Unfortunately it does cost money if you are using it for a commercial application, but they do provide a free non-commercial license.
Sox is a command-line tool which has an option to split an mp3 on n seconds of silence. You could always use the system command to call sox from c#.
Other related links.
Ripping a CD to mp3 in C# - third party component or api out there?
Audio Libraries for MP3 editing
How do I merge/join mp3 files with c#
This code shows a way to make a CD
ripper in C#. There are APIs from some
vendors that allow reading audio CD
tracks but it is also possible to do
it using APIs that allow low level
access to CD drives such as ASPI from
Adaptec or IOCTL control codes. The
latter method is used in this case,
because there is no need to install
any third party software, it is
completely covered by Win32 API
functions.
http://www.codeproject.com/KB/cs/csharpripper.aspx
Splitting the MP3 stream will be difficult to do with any degree of precision. The compressed MP3 data exists as sequential chunks of audio data comprised of many samples. The easiest way to perform this would be to decode the stream either progressively or in its entirety, perform your manipulation, then re-encode it (which as I understand is how most jukebox software does it)
Having a solid knowledge of the file's binary format would be a good place to start. That done, you'll know what silence looks like in the file. You may have to define exactly what silence is. Presuming that, like most audio, it started from an analog source, there's almost certainly some noise buried in the "silence". What will your tolerance for ambient/background noise be?
Once you know what you're looking for, just scan through the file, looking for "it".
Simple ...
A program to do this already exists:
http://mp3splt.sourceforge.net/mp3splt_page/home.php
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.