Click here to Skip to main content
15,891,431 members
Articles / Programming Languages / C#

Parsing strong name signatures generated with sn.exe

Rate me:
Please Sign up or sign in to vote.
4.58/5 (14 votes)
4 May 20042 min read 115.1K   1.6K   25  
This article shows how to parse Assembly "strong name keyfiles" generated with sn.exe
//------------------------------------------------------------------------
// (c) 2002-2004 by Per Anderson.  All rights reserved.
//------------------------------------------------------------------------

using System;
using System.IO;
using System.Text;
using System.Xml; 
using System.Reflection;
using System.Security.Cryptography; 

using System.Collections;
using System.ComponentModel;



namespace Bullfrog.Compress.RSA
{

	

	public class Validator : RSA1024Util 
	{

		public Validator() : base()
		{
		}



		public Validator(string xmlkey) : base(xmlkey)
		{			
		}

		public Validator(byte[] snkbuf) : base(snkbuf)
		{
		}


	
		protected RSAPKCS1SignatureDeformatter _defmt = null; 
		protected RSAPKCS1SignatureDeformatter Defmt 
		{
			get
			{
				if (_defmt == null)
				{
					_defmt = new RSAPKCS1SignatureDeformatter(RSA); 
					_defmt.SetHashAlgorithm("SHA1"); 
				}
				return _defmt; 
			}
		}


		public virtual void SetKey(AsymmetricAlgorithm key)
		{
			Defmt.SetKey(key); 
		}


		public bool VerifySignature(string str_orig, byte[] signed)
		{
			if (_rsa == null) 
				return false; 
			
			byte[] orig = PlainTextToByte(str_orig); 			
			return VerifySignature(orig, signed); 			
		}

		public bool VerifySignature(string str_orig, string str_signed)
		{
			if (_rsa == null) 
				return false; 
			
			byte[] orig = PlainTextToByte(str_orig); 
			byte[] signed = Base64StringToByte(str_signed); 			
			return VerifySignature(orig, signed); 
		}

		public bool VerifySignature(byte[] orig, byte[] signed)
		{
			if (_rsa == null) 
				return false; 

			if ((orig == null) || (orig.Length < 1)) return false;
			if ((signed == null) || (signed.Length < 1)) return false; 

			byte[] hash = SHA.ComputeHash(orig, 0, orig.Length);
			return Defmt.VerifySignature(hash, signed); 			
		}

	
	}

	
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Per Anderson is the founder of Sunfrog Technologies LLC, http://sunfrog-tech.com .

Comments and Discussions