コード例 #1
0
        public void CanSignAssembly(string inputAssembly, string outputAssembly)
        {
            string keyFile = Path.Combine(KeyDir, "test.snk");
            var    key     = new StrongNameKey(keyFile);

            var signer = new StrongNameSigner();

            signer.SignAssembly(inputAssembly, key, outputAssembly);

            if (Environment.OSVersion.Platform == PlatformID.Win32NT)
            {
                int exitCode = Exec.RunNetFxTool("sn.exe", new[] { "-v", outputAssembly });
                exitCode.Should()
                .Be(0);
            }

            PEReader assemblyReader = GetPEReader(outputAssembly);

            assemblyReader.PEHeaders.CorHeader.Flags.Should()
            .HaveFlag(CorFlags.StrongNameSigned);

            AssemblyName        assemblyName = GetAssemblyName(assemblyReader.GetMetadataReader());
            StrongNamePublicKey publicKey    = key.GetPublicKey();

            assemblyName.GetPublicKey()
            .Should()
            .BeEquivalentTo(publicKey.CreatePublicKey());

            assemblyName.GetPublicKeyToken()
            .Should()
            .BeEquivalentTo(publicKey.CreatePublicKeyToken());
        }
コード例 #2
0
        public void CanDelaySignAssembly(string inputAssembly, string outputAssembly)
        {
            string keyFile   = Path.Combine(KeyDir, "test_public_sha1.snk");
            var    publicKey = new StrongNamePublicKey(keyFile);

            var signer = new StrongNameSigner();

            signer.DelaySignAssembly(inputAssembly, publicKey, outputAssembly);

            PEReader assemblyReader = GetPEReader(outputAssembly);

            assemblyReader.PEHeaders.CorHeader.Flags.Should()
            .NotHaveFlag(CorFlags.StrongNameSigned);

            AssemblyName assemblyName = GetAssemblyName(assemblyReader.GetMetadataReader());

            assemblyName.GetPublicKey()
            .Should()
            .BeEquivalentTo(publicKey.CreatePublicKey());

            assemblyName.GetPublicKeyToken()
            .Should()
            .BeEquivalentTo(publicKey.CreatePublicKeyToken());
        }