Solved

Checking if file is tampered after encryption

Posted on 2007-12-04
4
319 Views
Last Modified: 2013-11-26
Hi,

I am using VB.NEt for a desktop app. Now I have a feature that will export the data into a text file which will be later encrypted. This encrypted file will be copied by the user on a drive and transferred to another PC. Here we will decrypt the file and import the data.

Now my question is: what if the encrypted file is opened by the user and changes made? Due to this, the import routine will get some junk data. Hence I want that after the file is encrypted, we want to take the CRC check and then before importing we again check the CRC to ensure that file is not tampered. How do we accomplish this in VB.NET? Alternately is there any other better way to ensure that file is tampered?

Regards,
mi
0
Comment
Question by:vj_mi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 9

Expert Comment

by:sognoct
ID: 20410509
md5 of a file is unique. So generating the md5 of the content will create an unique value (of fixed characters number)   that can be used as a crc.
Put that crc at the end of the file, or in the filename ad do the check on the other pc
0
 

Author Comment

by:vj_mi
ID: 20411716
But my file may be huge... say my employee table has 70,000 records. Now I write this data to the file. Now I want to generate crc for this complete file and not for the string. How do I write that md5 code. Second question is: if I add crc to the end of the file, how do I read it again?

Regards,
mi
0
 
LVL 9

Expert Comment

by:sognoct
ID: 20418627
ok ... so, md5 is unique also for 70.000 records.
You can put it on a new row at the end of the file, so just need to read it
fort the code of md5, are you using VB, c#, c++ ?
0
 
LVL 9

Accepted Solution

by:
sognoct earned 500 total points
ID: 20418684
the code for vb .net is :
Imports System
Imports System.Security.Cryptography
Imports System.Text
Imports System.Math
 
Public Class clsmd5
  Public Shared Function calculateMd5CRC(ByVal pfilename As String) As String
    Dim md5Hasher As MD5 = MD5.Create()
    Dim fs As System.IO.FileStream = System.IO.File.OpenRead(pfilename)
    Dim data As Byte() = md5Hasher.ComputeHash(fs)
    Return Convert.ToBase64String(data)
  End Function
End Class

Open in new window

0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question