Click here to Skip to main content
11,926,472 members (55,610 online)
Click here to Skip to main content
Add your own
alternative version


28 bookmarked

Is Someone Using Your Assembly? (SecUtil.exe .NET Framework Tools Series)

, 16 Jan 2006 CPOL
Rate this:
Please Sign up or sign in to vote.


There are a lot of assemblies that we create in our projects daily. Have we ever wondered that all those assemblies that we write after putting in such a lot of hard work and effort could be easily used by someone else. Also at times you don't want others to use a particular class or a method because it may retrieve some important or confidential information. .NET by itself works on the concept of sharing assemblies between applications which enables rapid application development (RAD). We can secure our code by identifying the caller.

Managed code offers several ways to restrict method access:

  • Limit the scope of accessibility to the class, assembly, or derived classes, if they can be trusted. This is the simplest way to limit method access. Note that, in general, derived classes can be less trustworthy than the class they derive from, though in some cases they share the parent class's identity. In particular, do not infer trust from the keyword protected, which is not necessarily used in the security context.
  • Limit the method access to callers of a specified identity -- essentially, any particular evidence (strong name, publisher, zone, and so on) you choose.
  • Limit the method access to callers having whatever permissions you select.

Let's see how we can accomplish this:

  1. Create a strong named assembly e.g. Calc.dll with one class called MyClass having the Add() method which adds two numbers.
  2. .NET Framework has a tool called SecUtil.exe.
  3. Go to the Visual Studio command prompt
  4. Type SecUtil.exe /?. This will display help and all the available options.
  5. Then type secutil.exe -s -hex -c Calc.dll (or the name of your DLL).
  6. This will display the public key as hexadecimal value as shown below:
C:\DotNet\DLLProj\bin\Debug>secutil -hex -c -s Calc.dll
Microsoft (R) .NET Framework SecUtil 1.1.4322.573
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.
Public Key =
Name =
Version =

Now You can use this public key with any class or method in your assembly that you don't want anyone else to access, you can use the StrongNameIdentityPermissionAttribute for this. Any calling code that isn't signed with your *.snk file won't have access to it.

Here I have used it at the class level. You can also achieve the same at the method or assembly level.

So, let's secure our class:

// put this code above the class as shown

PublicKey = 
"0x0024000004800000940000000602000000240000525341310004000001000100D96FE3B963FC64" +
"B8A9B6CA05B859A67B8B30603A0D696E1F95D8C9B23C5B2EEF139B96A5CC55C2E38D05B7FD675434" +

public class MyClass
public MyClass()

public int Add(int i , int j)
  1. Now create any Win app which will be a client app for this assembly.
  2. Do not strong name this assembly.
  3. Reference the above assembly in the client App.
  4. Call the Add method or any other method of Myclass.
  5. The code will compile.
  6. Try and execute the function call. You will get an error message similar to the one below:
Additional information: Request for the permission of 
type System.Security.Permissions.StrongNameIdentityPermission, mscorlib, 
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 failed.


  • 16th January, 2006: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Namratha Shah
United States United States
Namratha Shah a.k.a. Nasha is from orginally from Bombay, India but currently residing NJ, USA. She has to her credit, a Bachelor’s Degree in Microbiology and Biotechnology and a Master's in Computer and Software Applications (1999-2001) from Somaiya College Bombay. She started her career with C and C++ and then moved on to Microsoft Technologies. She has over 7.5 years experience in software architecture, design and development. She is a Certified Scrum Master and a member of the CORE .NET Architecture team. She has been Awarded with Microsoft’s Prestigious Most Valuable Professional (MVP) twice consecutively in years 2005 and 2006 in Visual C#.NET for her outstanding contributions to the .NET community.

You may also be interested in...

Comments and Discussions

QuestionFramwork version 4.0 Pin
lill.LEIF23-Mar-11 21:03
memberlill.LEIF23-Mar-11 21:03 
GeneralMy vote of 1 Pin
Member 307848118-Mar-09 22:51
memberMember 307848118-Mar-09 22:51 
GeneralIt doesnt work at all!! [modified] Pin
Member 307848118-Mar-09 22:33
memberMember 307848118-Mar-09 22:33 
GeneralNope...!!! Pin
AbhilashAshok1-Jan-08 0:37
memberAbhilashAshok1-Jan-08 0:37 
GeneralI don't recieve any Error Message Pin
ZarrinPour11-Feb-07 21:15
memberZarrinPour11-Feb-07 21:15 
GeneralRe: I don't recieve any Error Message Pin
BOB198323-Oct-07 12:04
memberBOB198323-Oct-07 12:04 
GeneralPeople can steal your code anyway Pin
Heinz_3-Aug-06 11:49
memberHeinz_3-Aug-06 11:49 
GeneralA few things to consider Pin
MrEyes17-Jan-06 5:26
memberMrEyes17-Jan-06 5:26 
GeneralPreventing someone from examine your original app and/or assemblies Pin
T-luv16-Jan-06 19:19
memberT-luv16-Jan-06 19:19 
Will the .NET obfuscator prevent someone from examine your original app and/or assemblies to ascertain the key?


don't spit into the wind... Jim Croce

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.151126.1 | Last Updated 16 Jan 2006
Article Copyright 2006 by Namratha Shah
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid