473,811 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Checksum, CRC or something better?

Bob
Hi there,

I am working on an application to be used in our local Forensics
department...

Among other things the app will connect to a digital camera and download the
images to the hard drive. For various reasons I need to be able to say with
certainty that the image on the hard drive is exactly what was on the
camera... any ideas on best way to achieve this...?

I could do a checksum of each image and compare this but not sure how to
implement in code or if there is a better way. Merely checking the file size
matches is not sufficient to stand up in Court.

Any suggestions appreciated, especially if sample code included (can be
classic VB if necessary). Does .Net perhaps have something like this built
into the Framework?

Cheers
Nov 20 '05
24 6852
Bob
Hi again Peter,

I have attempted to use this hashing code in the following scenario:

Get an image, base64 encode and write to xml file.

Reverse this process to get image file back.

Compare hashes of before and after - they do not match... image looks
identical visually, and has same filesize and other properties... can you
suggest a way I can store these images to an XML file and get the exact same
file back when I extract the image again...?

The XML code is something like this:

Private Sub WriteXMLImage(B yVal strSourceFilePa thAndName As String,
Optional ByVal strTargetFilePa thAndName As String = "")

If strSourceFilePa thAndName <> "" Then

Dim strSourceExtens ion As String = ""
strSourceExtens ion = strSourceFilePa thAndName.Subst ring
(strSourceFileP athAndName.Leng th - 3)

'Destination filename not supplied so make one up
If strTargetFilePa thAndName = "" Then
strTargetFilePa thAndName =
strSourceFilePa thAndName.Subst ring(0, strSourceFilePa thAndName.Lengt h
- 3)
& "xml"
End If

Dim xmlTextWriter As New XmlTextWriter
(strTargetFileP athAndName, Encoding.UTF8)
xmlTextWriter.F ormatting = Formatting.Inde nted
xmlTextWriter.W riteStartDocume nt()

' Copy the picture into a MemoryStream.
Dim memory_stream As New MemoryStream
Dim objImageOrigina l As Image

objImageOrigina l = New Bitmap(strSourc eFilePathAndNam e)
'objImageOrigin al = objImageOrigina l.FromFile
(strSourceFileP athAndName)
objImageOrigina l.Save(memory_s tream, GetFormat
(strSourceExten sion))

' Copy the MemoryStream data into a Byte array.
Dim objBytes(memory _stream.Length - 1) As Byte
objBytes = memory_stream.T oArray()

' Make a Picture element.
xmlTextWriter.W riteStartElemen t("Picture")
xmlTextWriter.W riteAttributeSt ring("Encoding" ,
Nothing,
"Base64")
' Save Image details and encoding as Attributes

xmlTextWriter.W riteAttributeSt ring("Bytes",
objBytes.Length )
xmlTextWriter.W riteAttributeSt ring("Height",
objImageOrigina l.Height)
xmlTextWriter.W riteAttributeSt ring("Width",
objImageOrigina l.Width)
xmlTextWriter.W riteAttributeSt ring("Type",
strSourceExtens ion)
xmlTextWriter.W riteBase64(objB ytes, 0, objBytes.Length )
xmlTextWriter.W riteEndElement( )
xmlTextWriter.W riteEndDocument ()

xmlTextWriter.C lose()
objImageOrigina l.Dispose()
MsgBox("XML file created successfully ! ",
MsgBoxStyle.Inf ormation, "Success !")

Else
MsgBox("A target file name must be supplied.",
MsgBoxStyle.OKO nly + MsgBoxStyle.Exc lamation, "Error")
Exit Sub
End If

End Sub

Private Sub ReadXMLImage(By Val strSourceFilePa thAndName As String)

If strSourceFilePa thAndName <> "" Then

Dim objImageOrigina l As Image
Dim blnValidXML As Boolean = False
Dim strImageExtensi on As String = ""
Dim strTargetFilePa thAndName As String = ""

' Load the picture from XML
Dim xmlTextReader As New XmlTextReader
(strSourceFileP athAndName)

' Skip until we find the Picture node.
Do While xmlTextReader.R ead()
' See if this is the Picture node.
If xmlTextReader.N ame = "Picture" Then
blnValidXML = True
' Allocate room for the byte data and get all
attribute
values.
Dim intNumBytes As Integer =
xmlTextReader.G etAttribute
("Bytes")
Dim h As Integer =
xmlTextReader.G etAttribute("He ight")
Dim w As Integer =
xmlTextReader.G etAttribute("Wi dth")

strImageExtensi on =
xmlTextReader.G etAttribute("Ty pe")

'Refresh the target file according to parameters
read
from XML file Type Attribute
strTargetFilePa thAndName = Replace
(strSourceFileP athAndName, ".xml", "New." &
strImageExtensi on)
'lbl_Message.Te xt = "Source File : " &
strSourceFilePa thAndName & vbCrLf & "Target File : " &
strTargetFilePa thAndName

Dim bytes(intNumByt es - 1) As Byte

' Translate the encoded data back into byte data.
Select Case xmlTextReader.G etAttribute
("Encoding").To Lower
Case "base64"
xmlTextReader.R eadBase64(bytes , 0,
intNumBytes)
Case "binhex"
xmlTextReader.R eadBinHex(bytes , 0,
intNumBytes)
Case Else
MsgBox("Unknown image encoding
'" &
xmlTextReader.G etAttribute("En coding") & "'", _
MsgBoxStyle.Exc lamation, "Unknown
Encoding")
Exit Sub
End Select

' Allocate a MemoryStream and a BinaryWriter
attached
to it.
Dim memory_stream As New MemoryStream
Dim binary_writer As BinaryWriter = New
BinaryWriter
(memory_stream)

' Copy the bytes into the BinaryWriter and
MemoryStream.
binary_writer.W rite(bytes, 0, intNumBytes)
binary_writer.F lush()

' Load the picture from the memory stream and
save it
and show in the Picture box.
memory_stream.P osition = 0
objImageOrigina l = Image.FromStrea m(memory_stream )

'objImageOrigin al.Save(strTarg etFilePathAndNa me,
GetFormat(strIm ageExtension))
objImageOrigina l.Save(strTarge tFilePathAndNam e)
'Me.PB_sample.I mage =
Image.FromStrea m(memory_stream )
'PB_sample.Size Mode =
PictureBoxSizeM ode.CenterImage
binary_writer.C lose()
Exit Do
End If
Loop

xmlTextReader.C lose()
If blnValidXML Then
MsgBox(strImage Extension.ToUpp er & " file created
successfully ! ", MsgBoxStyle.Inf ormation, "Success !")
Else
MsgBox("Invalid XML file format ! ",
MsgBoxStyle.Cri tical,
"Error !")
End If

Else
MsgBox("An xml file containing the image must be
selected.",
MsgBoxStyle.OKO nly + MsgBoxStyle.Inf ormation, "File error")
Exit Sub
End If

End Sub

Private Function GetFormat(ByVal ImageType As String) As
System.Drawing. Imaging.ImageFo rmat
Select Case ImageType.ToUpp er
Case "JPG"
Return ImageFormat.Jpe g
Case "GIF"
Return ImageFormat.Gif
Case "PNG"
Return ImageFormat.Png
Case "BMP"
Return ImageFormat.Bmp
End Select
End Function

Also, I want (need) to do this for image formats that aren't recognised by
the image object (Wavelet Scalar Quantization .wsq format)... any idea how I
can achieve this?

Cheers again for you help...
"Peter Huang" <v-******@online.m icrosoft.com> wrote in message
news:7y******** ******@cpmsftng xa06.phx.gbl...
Hi Bob,

If you have any question on this issue please post here.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #21
Hi Bob,

Here is my code snipper.
Dim writer As New XmlTextWriter(" c:\test.xml",
System.Text.Enc oding.UTF8)
writer.WriteSta rtElement("ss")
writer.WriteBas e64(arr, 0, len)
writer.WriteEnd Element()
writer.Close()
Dim readoutbuffer(l en) As Byte
Dim reader As New XmlTextReader(" c:\test.xml")
reader.Read()
Dim rt As Integer = reader.ReadBase 64(readoutbuffe r, 0, len)
reader.Close()

I think the WriteBase64 of XmlTextWriter and the ReadBase64 of
XmlTextReader is what you want.
For more information, you may refer to the two methods in MSDN.
Please have a try and let me know the result.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #22
Bob
Peter, you're too much...

Thanks again for your help... I was looking at this myself but hadn't got it
to work completely (was trying with filestream object)...

Cheers
"Peter Huang" <v-******@online.m icrosoft.com> wrote in message
news:wW******** ******@cpmsftng xa06.phx.gbl...
Hi Bob,

Here is my code snipper.
Dim writer As New XmlTextWriter(" c:\test.xml",
System.Text.Enc oding.UTF8)
writer.WriteSta rtElement("ss")
writer.WriteBas e64(arr, 0, len)
writer.WriteEnd Element()
writer.Close()
Dim readoutbuffer(l en) As Byte
Dim reader As New XmlTextReader(" c:\test.xml")
reader.Read()
Dim rt As Integer = reader.ReadBase 64(readoutbuffe r, 0, len)
reader.Close()

I think the WriteBase64 of XmlTextWriter and the ReadBase64 of
XmlTextReader is what you want.
For more information, you may refer to the two methods in MSDN.
Please have a try and let me know the result.
Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #23
Hi Bob,

Actually your code works well on my machines.
e.g.
the WriteXMLImage will write dafen.jpg into the dafen.xml
the ReadXMLImage will read dafen.xml and create a new file dafenNew.jpg

I then computer the two files dafen.jpg and dafenNew.jpg 's hash code ,
they are match.

I post my code snipper in the previous post, I hope you can creatd a simple
test project as what I did.
To isolate the problem, my idea is that write the jpg file into the xml
file and then read it back from the xml file.
Then you will know if there is any wrong with XMLwrite and XMLread steps.

I look forward to hearing from you.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #24
Bob
Well, good to know you can get it to work... not sure why I had problems...
it did store the image to XML and recover it fine... the image opened and
looked identical... it was only the hash value that differed.

Still, your code is absolute simplicity compared to what I was using... it
works a treat...

If I can only get around the CD Writing issue I'll pretty much have a fully
functional prototype...

Cheers Peter...

"Peter Huang" <v-******@online.m icrosoft.com> wrote in message
news:gI******** *****@cpmsftngx a06.phx.gbl...
Hi Bob,

Actually your code works well on my machines.
e.g.
the WriteXMLImage will write dafen.jpg into the dafen.xml
the ReadXMLImage will read dafen.xml and create a new file dafenNew.jpg

I then computer the two files dafen.jpg and dafenNew.jpg 's hash code ,
they are match.

I post my code snipper in the previous post, I hope you can creatd a simple test project as what I did.
To isolate the problem, my idea is that write the jpg file into the xml
file and then read it back from the xml file.
Then you will know if there is any wrong with XMLwrite and XMLread steps.

I look forward to hearing from you.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #25

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

Similar topics

3
1309
by: Robert Oschler | last post by:
I'm about to do some MySQL work with Python. In the Python Cookbook book they talk about the MySQLdb module. Is that still the way to go or is there something better (easier, newer, etc.)? Thanks. -- Robert
2
2057
by: PyongHopscotch | last post by:
Hi All I was just wondering if there was a better function/way to get information on all the printers currently installed than EnumPrinters. I only really need all the printer names but don't care to do the memory management involved with EnumPrinters. I looked at using GetProfileString with but that requires I know the buffer size ahead of time. Any alternatives would be appreciated.
3
2797
by: PyongHopscotch | last post by:
Hi All I was just wondering if there was a better function/way to get information on all the printers currently installed than EnumPrinters. I only really need all the printer names but don't care to do the memory management involved with EnumPrinters. I looked at using GetProfileString with but that requires I know the buffer size ahead of time. Any alternatives would be appreciated
3
1938
by: MikeY | last post by:
From my understanding when exporting your app.exe with a mediaplay hooked up, you must also place a copy of AxInterop.WMPLib.dll and Interop.WMPLib.dll" wrapper class. to the location of my app.exe. Is there something better out there I should be using to avoid this and or a better way of doing this so that I don't have to export the .dll's. Any and all help is appreciated. MikeY
0
1856
by: sloan | last post by:
I've been reading this article: http://msdn2.microsoft.com/EN-US/library/aa302401.aspx Building Secure ASP.NET Applications: Authentication, Authorization, and Secure Communication (the article is for 1.1) (i'm using 2.0) The article is good. Then you get to the part about:::::::::::::
6
2356
by: buu | last post by:
I'm using getHashCode sub from String object, but sometimes it gives me duplicate values for different strings. Difference is always when there are some numbers in strings. Is there any better/new getHash code function or any way to do some better hashing?
0
9728
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
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10648
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...
0
10389
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9205
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
6890
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
5554
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...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.