473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Determin if a binary file is encrypted

Hi,

I wote some code that encrypts binary files, and decrypts them, works
great. It uses the same file name, so if the file is called
mountain.jpg, it encrypts it with the same name.

I'm using Rijndael, is there a script I can write that can tell if the
file is encrypted before i try to read it into a picturebox or
something.

One way i can tell is it error on load as not a valid image, but i
want to be able to do it with all files.

Thanks !

Aug 1 '08 #1
3 4284
TheLostLeaf wrote:
I wote some code that encrypts binary files, and decrypts them, works
great. It uses the same file name, so if the file is called
mountain.jpg, it encrypts it with the same name.

I'm using Rijndael, is there a script I can write that can tell if the
file is encrypted before i try to read it into a picturebox or
something.

One way i can tell is it error on load as not a valid image, but i
want to be able to do it with all files.
In general: no. There is nothing preventing that the same file
can be both an encrypted file and an image. So you can not
distinguish.

If you are willing to limit yourself to a small set of
graphics formats, then you can check if the file matches
a header for that file type (magic value and other known
values).

Arne

Aug 1 '08 #2
On Aug 1, 12:11*pm, Arne Vajhøj <a...@vajhoej.dkwrote:
TheLostLeaf wrote:
I wote some code that encrypts binary files, and decrypts them, works
great. It uses the same file name, so if the file is called
mountain.jpg, it encrypts it with the same name.
I'm using Rijndael, is there a script I can write that can tell if the
file is encrypted before i try to read it into a picturebox or
something.
One way i can tell is it error on load as not a valid image, but i
want to be able to do it with all files.

In general: no. There is nothing preventing that the same file
can be both an encrypted file and an image. So you can not
distinguish.

If you are willing to limit yourself to a small set of
graphics formats, then you can check if the file matches
a header for that file type (magic value and other known
values).

Arne
Thanks, I think i will rename the file with an extra extention, like
mountain.jpg.enc. I didn't know if I could same the BOF or EOF for a
tell take char that might occur with any Rijndael encrypt.

Aug 1 '08 #3
On Fri, 01 Aug 2008 12:00:29 -0700, TheLostLeaf <er**@canyondigital.com>
wrote:
I wote some code that encrypts binary files, and decrypts them, works
great. It uses the same file name, so if the file is called
mountain.jpg, it encrypts it with the same name.

I'm using Rijndael, is there a script I can write that can tell if the
file is encrypted before i try to read it into a picturebox or
something.

One way i can tell is it error on load as not a valid image, but i
want to be able to do it with all files.
You can follow a filename convention, but of course that will only work as
long as no one changes the file name.

My general approach when encoding data is to attempt to decode the data in
the deepest encoding first, and work my way back. So in your case, rather
than trying to load the data as an image, you should be trying to decrypt
it. If the decryption fails, then you know it's _not_ encrypted and so
can move on to the next likely stage (e.g. loading it as an image).

If you knew the data was only one of two formats, you could do either
attempt first. But you might as well rule out the encryption first, since
that will tell you for any file whether it's been encrypted or not.

Pete
Aug 1 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Kevin Knorpp | last post by:
Hello. I need to be able to extract the data from the attached file (or any file in the same format) so that I can work with the data in PHP. I'm fairly comfortable with using PHP with...
3
by: Phil Palmieri | last post by:
Im using md5 to encrypt and decrypt plain text, this works fine... When i try to run the same function on a binary file, it does not decrypt correctly. Is there a way to encrypt binary files...
0
by: chris | last post by:
I'm writing a small app to help me learn more about cryptography. All it does is encrypt all of the files in directory A, and put the encrypted versions of the files in directory B. It then...
3
by: I_AM_DON_AND_YOU? | last post by:
In my program I am using the notepad file to read/write data. I don't want that someone should be able to delete/change the contents of that file by opening that file in Notepad or other editor. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.