473,654 Members | 3,076 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4303
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.d kwrote:
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.en c. 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**@canyondig ital.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
3765
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 databases, arrays, etc. but have not worked with binary data files. http://www.performancecentral.net/C...3Loop/3Loop.php click on "Download Performance".
3
10411
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 correctly, and be able to decrypt them? in the perfect situation i would like to be able to store the encrypted binary file into a mysql blob field, or at least be able to save an encrypted version of the binary file on the server.
0
8232
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 decrypts the files in directory B, and puts them in directory C. I'm getting some exceptions when I try to decrypt a binary file though. Here's the code: ////////////////////////////////////////////////////////////////////// public class...
3
7155
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. Like there is a feature in Word to put password to open your document. I want to do something like that in Notepad file because I can't store the data in word file (in binary format) because I am using stream reader/write object. Is there any...
0
8375
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8815
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8482
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8593
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7306
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5622
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1916
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1593
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.