Пример #1
0
        public int Execute(CommandLineApplication cmd)
        {
            bool   force   = _force.HasValue();
            int?   keySize = _keySize.HasValue() ? _keySize.ParsedValue : (int?)null;
            string keyFile = _keyFile.Value;

            try
            {
                if (File.Exists(keyFile) && !force)
                {
                    throw new FileAlreadyExistsException(keyFile);
                }

                StrongNameKey key = _keyGenerator.Generate(keySize);
                File.WriteAllBytes(keyFile, key.CreateStrongName());
            }
            catch (Exception error)
            {
                cmd.Error.WriteLine("ERROR: {0}", error.Message);
                return(ExitCodes.FromException(error));
            }

            cmd.Out.WriteLine("Key pair written to '{0}'.", keyFile);
            return(ExitCodes.Success);
        }
Пример #2
0
        public void GeneratesKeyWhichSnCanExport()
        {
            Skip.IfNot(Environment.OSVersion.Platform == PlatformID.Win32NT);

            string keyFile       = nameof(GeneratesKeyWhichSnCanExport) + ".snk";
            string publicKeyFile = nameof(GeneratesKeyWhichSnCanExport) + "_public.snk";

            var           generator = new StrongNameKeyGenerator();
            StrongNameKey key       = generator.Generate();

            File.WriteAllBytes(keyFile, key.CreateStrongName());

            int exitCode = Exec.RunNetFxTool("sn.exe", new[] { "-p", keyFile, publicKeyFile });

            exitCode.Should()
            .Be(0);
        }