Mono.Security.StrongName.Verify C# (CSharp) Method

Verify() static private method

static private Verify ( RSA rsa, AssemblyHashAlgorithm algorithm, byte hash, byte signature ) : bool
rsa RSA
algorithm AssemblyHashAlgorithm
hash byte
signature byte
return bool
		static private bool Verify (RSA rsa, AssemblyHashAlgorithm algorithm, byte[] hash, byte[] signature) 
		{
			RSAPKCS1SignatureDeformatter vrfy = new RSAPKCS1SignatureDeformatter (rsa);
			switch (algorithm) {
			case AssemblyHashAlgorithm.MD5:
				vrfy.SetHashAlgorithm ("MD5");
				break;
			case AssemblyHashAlgorithm.SHA1:
			case AssemblyHashAlgorithm.None:
			default:
				vrfy.SetHashAlgorithm ("SHA1");
				break;
			}
			return vrfy.VerifySignature (hash, signature);
		}
	}

Same methods

StrongName::Verify ( Stream stream ) : bool
StrongName::Verify ( string fileName ) : bool

Usage Example

コード例 #1
0
        // We don't want a dependency on StrongNameManager in Mono.Security.dll
        static public bool IsAssemblyStrongnamed(string assemblyName)
        {
            if (!initialized)
            {
                lock (lockObject)
                {
                    if (!initialized)
                    {
#if NET_2_1
                        // Moonlight cannot depend on machine.config
#else
                        string config = Environment.GetMachineConfigPath();
                        StrongNameManager.LoadConfig(config);
#endif
                        initialized = true;
                    }
                }
            }

            try
            {
                // this doesn't load the assembly (well it unloads it ;)
                // http://weblogs.asp.net/nunitaddin/posts/9991.aspx
                AssemblyName an = AssemblyName.GetAssemblyName(assemblyName);
                if (an == null)
                {
                    return(false);
                }

                byte[] publicKey = StrongNameManager.GetMappedPublicKey(an.GetPublicKeyToken());
                if ((publicKey == null) || (publicKey.Length < 12))
                {
                    // no mapping
                    publicKey = an.GetPublicKey();
                    if ((publicKey == null) || (publicKey.Length < 12))
                    {
                        return(false);
                    }
                }

                // Note: MustVerify is based on the original token (by design). Public key
                // remapping won't affect if the assembly is verified or not.
                if (!StrongNameManager.MustVerify(an))
                {
                    return(true);
                }

                RSA        rsa    = CryptoConvert.FromCapiPublicKeyBlob(publicKey, 12);
                StrongName sn     = new StrongName(rsa);
                bool       result = sn.Verify(assemblyName);
                return(result);
            }
            catch
            {
                // no exception allowed
                return(false);
            }
        }
All Usage Examples Of Mono.Security.StrongName::Verify