Avatar of japhethdleung
japhethdleung

asked on 

How can I get the FILE SIGNATURE?

Hello,

Anyone have an idea how can we detect the file extension of a certain type without looking to its extension value?

Thanks
Japheth
.NET ProgrammingC#

Avatar of undefined
Last Comment
ad5qa
Avatar of ad5qa
ad5qa
Flag of United States of America image

the file header first 20 bytes

Then you need to get the signatures and look them up. Should get you started.
FileStream fs = File.Open(path, FileMode.Open);
Byte[] b = new byte[20];
fs.Read(b, 0, 20);

Open in new window

Avatar of japhethdleung
japhethdleung

ASKER

Does all file have on header in first 20byte???
Avatar of ad5qa
ad5qa
Flag of United States of America image

That will get you the filetype for the file without checking the extension. For example I cant send .exe in my email. Some users change the .exe to .txt to fake the filetype. Good firewalls and sensors don't rely on the .extension but will check the header and file checksum.  The first 20 bytes will get you the file type but with a hex editor or similar program. The checksum helps validate against this type of change. Of course to ensure the correct delivery you will see MD5 public hash keys to match the program to. Many open source programs will distribute the program with a md5 hash. The user will then use a md5 generator and confirm the match which validates that not one byte has been modified from the original.
Avatar of japhethdleung
japhethdleung

ASKER

Thaks for that info...

Can you give me a sample code for that.
ASKER CERTIFIED SOLUTION
Avatar of ad5qa
ad5qa
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo