Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

programmatically determine if *.ts video file is encrypted with aes 128

I want to write a simple automated test to determine if a .ts video file has been encrypted using AES 128 encryption. I will have access to both the encrypted and unencrypted files. I will also have access to the key. I will pretty much have access to everything because I am working with the developers doing the encryption :)

I'd prefer to do a test more advanced than just checking to see if the file sizes are different.

Any thoughts on some simple test code I could write? I'd be writing the code with c# or powershell.

I have absolutely no experience with this stuff so feel free to treat me like a child.

Thanks

like image 933
user952342 Avatar asked Dec 13 '25 15:12

user952342


2 Answers

What's the real reason behind this? So you don't encrypt a file twice, or decrypt twice? Perhaps there's a better solution if we know the requirements.

However, based on what I see so far, it seems like you'll have to attempt to decrypt the file and if it fails, assume it's not encrypted … but this could be very time consuming. I am not sure if there's any other way, other than opening the file for reading, read a line and see if there is any plaintext, assuming you know what plaintext to compare it against.

If you are attempting to test if encryption/decryption is working properly, then you could take an input file with known plaintext, encrypt it with the correct key, then decrypt it twice - once with the correct key, the second time with an invalid key. Compare the results 3 ways.

like image 79
Richard Anthony Freeman-Hein Avatar answered Dec 15 '25 06:12

Richard Anthony Freeman-Hein


If the TS container is entirely encrypted then it would probably be more efficient to see if the file is a valid MPEG-TS file instead of trying to figure out if it's encrypted or not. If it's invalid, assume it's encrypted. You can read the first couple of bytes of the file to validate the format. The format (or "magic numbers") is documented here:

http://en.wikipedia.org/wiki/MPEG_transport_stream#Packet

Hope this helps.

like image 43
x0n Avatar answered Dec 15 '25 06:12

x0n



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!