// 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); } }
public static bool IsAssemblyStrongnamed(string assemblyName) { if (!StrongName.initialized) { object obj = StrongName.lockObject; lock (obj) { if (!StrongName.initialized) { StrongName.initialized = true; } } } bool result; try { AssemblyName assemblyName2 = AssemblyName.GetAssemblyName(assemblyName); if (assemblyName2 == null) { result = false; } else { byte[] mappedPublicKey = StrongNameManager.GetMappedPublicKey(assemblyName2.GetPublicKeyToken()); if (mappedPublicKey == null || mappedPublicKey.Length < 12) { mappedPublicKey = assemblyName2.GetPublicKey(); if (mappedPublicKey == null || mappedPublicKey.Length < 12) { return(false); } } if (!StrongNameManager.MustVerify(assemblyName2)) { result = true; } else { RSA rsa = CryptoConvert.FromCapiPublicKeyBlob(mappedPublicKey, 12); StrongName strongName = new StrongName(rsa); bool flag = strongName.Verify(assemblyName); result = flag; } } } catch { result = false; } return(result); }