473,467 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Hash Checking On Startup

Hi, I'm trying to implement a way to security check the Hash of the
Application.ExecutablePath. I placed the following ran the ff
procedure at Sub Main

Private Sub CheckHash()
Dim fs As New System.IO.FileStream(Application.ExecutablePath,
System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim shaM As New System.Security.Cryptography.SHA512Managed
Dim bt As Byte() = shaM.ComputeHash(fs)
Console.WriteLine(BitConverter.ToString(bt))

Dim test As String =
"68-B4-A8-E1-FB-A7-5A-76-A9-26-4E-71-F1-7F-1F-93-9F-74-AF-6F-80-A4-A1-AC-34-89-11-8E-43-E7-34-77-BD-B4-6F-1C-B9-C3-F7-29-63-DD-EA-1C-FF-93-6E-18-49-1C-D2-9C-42-10-FD-0D-C3-AC-E5-42-D5-44-9E-E4"
If BitConverter.ToString(bt) = test Then
MsgBox("Same")
Else
MsgBox("Not The same")
End If
fs.Close()
End Sub
My problem is that whenever I generate the Hash value for
MyApplication.exe and store it at Dim test As String ="....." the
value of BitConverter.ToString(bt) changes, thus it would not match no
matter what I do.

Any insights on how to check the MyApplication.exe executable on
StartUp?

Thanks,
Henry
Nov 21 '05 #1
5 1286
Give your assembly a Strong Name (read the docs) and the .NET framework will
perform the integrity validation for you when the assembly is loaded.

--

Carlos J. Quintero (Visual Developer - .NET MVP)

The MZ-Tools all-in-one add-in, now for .NET: http://www.mztools.com
"Henry C. Wu" <he***********@gmail.com> escribió en el mensaje
news:44**************************@posting.google.c om...
Hi, I'm trying to implement a way to security check the Hash of the
Application.ExecutablePath. I placed the following ran the ff
procedure at Sub Main

Private Sub CheckHash()
Dim fs As New System.IO.FileStream(Application.ExecutablePath,
System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim shaM As New System.Security.Cryptography.SHA512Managed
Dim bt As Byte() = shaM.ComputeHash(fs)
Console.WriteLine(BitConverter.ToString(bt))

Dim test As String =
"68-B4-A8-E1-FB-A7-5A-76-A9-26-4E-71-F1-7F-1F-93-9F-74-AF-6F-80-A4-A1-AC-34-
89-11-8E-43-E7-34-77-BD-B4-6F-1C-B9-C3-F7-29-63-DD-EA-1C-FF-93-6E-18-49-1C-D
2-9C-42-10-FD-0D-C3-AC-E5-42-D5-44-9E-E4" If BitConverter.ToString(bt) = test Then
MsgBox("Same")
Else
MsgBox("Not The same")
End If
fs.Close()
End Sub
My problem is that whenever I generate the Hash value for
MyApplication.exe and store it at Dim test As String ="....." the
value of BitConverter.ToString(bt) changes, thus it would not match no
matter what I do.

Any insights on how to check the MyApplication.exe executable on
StartUp?

Thanks,
Henry

Nov 21 '05 #2
Hi, thanks for the tip.

I'm following the article on how to give your .NET assembly a Strong
Name.
http://www.codeguru.com/columns/Expe...cle.php/c4643/
Specifically the procedure to use when obfuscating your assembly.

'Begin Snippet------------------------------

Practically, this means that you end up using the delay-signing
process when obfuscating an assembly with a strong name. The typical
usage pattern for a developer using obfuscation is:

a) Build the assembly with delay signing enabled.
b) Enable strong name verification skipping for the assembly (sn.exe
-Vr).
c) Debug and test the assembly.
d) Obfuscate the assembly.
e) Debug and test the obfuscated version.
f) Delay sign the assembly (sn.exe -R).

'End Snippet------------------------------

My Question is
1) How do you "embed" the PublicPrivateKeyFile.snk to the VB Solution?
What I mean is for example you will distribute your application, will
you distribute it with the PublicPrivateKeyFile.snk on the same
directory with your EXE application?

2) After creating the PublicPrivateKeyFile.snk using SN.exe, I copy &
pasted it to my Project's Solution directory & BIN directory,...

doing the follwoing would result to an error:
<Assembly: AssemblyKeyFile("PublicPrivateKeyFile.snk")>

but doing this corrected the error:
<Assembly: AssemblyKeyFile("E:\My Projects\Visual
Basic\vbVideoPatternGenerator\bin\PublicPrivateKey File.snk")>

I've been reading the Visual Studio .NET help, & it says there that
VB's IDE will automatically check for it under your project's Solution
directory. I wonder why it still renedered that error.

3)Step B on the Snippet above,..is the following correct to apply
verification skipping for my assembly?

sn.exe -Vr E:\My Projects\Visual
Basic\vbVideoPatternGenerator\bin\vbMyProject.exe

Is this the correct way? I'm in doubt a bit because the example was:
sn.exe -Vr YourAssembly.dll

But my assembly doesnt have a DLL.

4)Lastly, when accomplishing everything above. How can I check if I
have done the correct procedure? I mean is there a way to "test" & see
if the assembly is manipulated,...then the application *must not*
start.

Thanks, I appreciate if someone will help me out here in detail
because this is new to me.

Thanks,
Henry
Nov 21 '05 #3
Hi, thanks for the tip.

I'm following the article on how to give your .NET assembly a Strong
Name.
http://www.codeguru.com/columns/Expe...cle.php/c4643/
Specifically the procedure to use when obfuscating your assembly.

'Begin Snippet------------------------------

Practically, this means that you end up using the delay-signing
process when obfuscating an assembly with a strong name. The typical
usage pattern for a developer using obfuscation is:

a) Build the assembly with delay signing enabled.
b) Enable strong name verification skipping for the assembly (sn.exe
-Vr).
c) Debug and test the assembly.
d) Obfuscate the assembly.
e) Debug and test the obfuscated version.
f) Delay sign the assembly (sn.exe -R).

'End Snippet------------------------------

My Question is
1) How do you "embed" the PublicPrivateKeyFile.snk to the VB Solution?
What I mean is for example you will distribute your application, will
you distribute it with the PublicPrivateKeyFile.snk on the same
directory with your EXE application?

2) After creating the PublicPrivateKeyFile.snk using SN.exe, I copy &
pasted it to my Project's Solution directory & BIN directory,...

doing the follwoing would result to an error:
<Assembly: AssemblyKeyFile("PublicPrivateKeyFile.snk")>

but doing this corrected the error:
<Assembly: AssemblyKeyFile("E:\My Projects\Visual
Basic\vbVideoPatternGenerator\bin\PublicPrivateKey File.snk")>

I've been reading the Visual Studio .NET help, & it says there that
VB's IDE will automatically check for it under your project's Solution
directory. I wonder why it still renedered that error.

3)Step B on the Snippet above,..is the following correct to apply
verification skipping for my assembly?

sn.exe -Vr E:\My Projects\Visual
Basic\vbVideoPatternGenerator\bin\vbMyProject.exe

Is this the correct way? I'm in doubt a bit because the example was:
sn.exe -Vr YourAssembly.dll

But my assembly doesnt have a DLL.

4)Lastly, when accomplishing everything above. How can I check if I
have done the correct procedure? I mean is there a way to "test" & see
if the assembly is manipulated,...then the application *must not*
start.

Thanks, I appreciate if someone will help me out here in detail
because this is new to me.

Thanks,
Henry
Nov 21 '05 #4
Hi,
1) How do you "embed" the PublicPrivateKeyFile.snk to the VB Solution?
What I mean is for example you will distribute your application, will
you distribute it with the PublicPrivateKeyFile.snk on the same
directory with your EXE application?
You don´t need to add it. You just set the <Assembly: AssemblyKeyFile>
attribute in the AssemblyInfo.vb file pointing to that file. The .snk is
only needed by the VS.NET when building the assembly, but it is not needed
by the executable once built (so you don´t copy it to the Bin folder).
2) After creating the PublicPrivateKeyFile.snk using SN.exe, I copy &
pasted it to my Project's Solution directory & BIN directory,...
See previous paragraph about the bin folder
doing the follwoing would result to an error:
<Assembly: AssemblyKeyFile("PublicPrivateKeyFile.snk")>

but doing this corrected the error:
<Assembly: AssemblyKeyFile("E:\My Projects\Visual
Basic\vbVideoPatternGenerator\bin\PublicPrivateKey File.snk")>

I've been reading the Visual Studio .NET help, & it says there that
VB's IDE will automatically check for it under your project's Solution
directory. I wonder why it still renedered that error.
There is a bug in the docs. Try adding \.. until it works:

<Assembly: AssemblyKeyFile("PublicPrivateKeyFile.snk")>
<Assembly: AssemblyKeyFile("..\PublicPrivateKeyFile.snk")>
<Assembly: AssemblyKeyFile("..\..\PublicPrivateKeyFile.snk")>
3)Step B on the Snippet above,..is the following correct to apply
verification skipping for my assembly?

sn.exe -Vr E:\My Projects\Visual
Basic\vbVideoPatternGenerator\bin\vbMyProject.exe

Is this the correct way? I'm in doubt a bit because the example was:
sn.exe -Vr YourAssembly.dll

But my assembly doesnt have a DLL.
Yes, it sn.exe -Vr <assembly> is correct.
4)Lastly, when accomplishing everything above. How can I check if I
have done the correct procedure? I mean is there a way to "test" & see
if the assembly is manipulated,...then the application *must not*
start.


Yes.

sn.exe -v or sn.exe -vf verify the strong name of the assembly. Type sn.exe
/? to see the command line options usage.

The ultimate proof is to use an hex editor and change a character of a
string of your assembly, for example changing the case. The exe should give
an error when launched.

--

Carlos J. Quintero (Visual Developer - .NET MVP)

The MZ-Tools all-in-one add-in, now for .NET: http://www.mztools.com

Nov 21 '05 #5
Thanks so much for info!!! I appreciate it! My assembly is now
obfuscated & strong named.

Thanks again,
Henry
Nov 21 '05 #6

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

Similar topics

3
by: Daniel | last post by:
right now i have some sql server tables that i search for a value w/ a key each time a .aspx is hit. is there any way i can just have the first hit to the .aspx select all the entries from the...
7
by: User | last post by:
Hi, A page I have shows a different background colour depending on the hash portion of the url as it is first loaded. For example a link to mysite/mypage#0000FF would result in a page with a blue...
6
by: Joseph Lee | last post by:
Dear All, Is there a function in C# that will hash code a large byte array into an int value? I am searching for a hash function that will convert any size data(as for me the input is a byte...
12
by: wxs | last post by:
Many times we have a bunch of enums we have from either different enums or the same enum that will have various numeric values assigned. Rarely will there be collisions in numbering between the...
1
by: sympatico | last post by:
Hi, I am trying to compare 2 images to check if they are exactly identical (in terms of data), I thought this would be quicker than analysing pixels of the images. I have found lots of examples...
1
by: c676228 | last post by:
Hi, I have met this problem for many times, I don't how to fix it, the only thing I can do is to restart the computer. Here is the case: Sometimes when I change the behide class code, and then...
8
by: mortb | last post by:
Hi, How do I write a GenerateHashcode function that will generate guaranteed unique hashcodes for my classes? cheers, mortb
11
by: merrittr | last post by:
Hi in the code below in the main the hash table from K&R example replaces a node when a collision occurs What I am trying to do is set it up to "chain" another structure beside the node that it...
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
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
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...
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,...
1
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...
0
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...
0
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,...
0
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...
0
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...
0
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 ...

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.