コード例 #1
0
ファイル: Program.cs プロジェクト: virl/yttrium
        /// <summary>
        /// Точка входа в программу.
        /// </summary>
        /// <param name="args">Аргументы:
        /// 1. Имя xml-файла с закрытым ключом.
        /// 2. Имя клиента.
        /// 3. E-mail клиента.
        /// 4. Дата выдачи лицензии.
        /// 5. Длительность лицензии.
        /// 6. Количество компьютеров.
        /// </param>
        static int Main(string[] args)
        {
            if (args.Length > 0 && args[0].Equals("-p"))
                return GenerateKey(args);

            if (args.Length < 6)
                return 1;

            FileStream fs = new FileStream(args[0], FileMode.Open);
            StreamReader sr = new StreamReader(fs);

            StringBuilder xmlkey = new StringBuilder("");
            string s;
            while( (s = sr.ReadLine()) != null )
            {
                xmlkey.AppendLine(s);
            }

            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            rsa.FromXmlString(xmlkey.ToString());

            LicenseInfo license = new LicenseInfo();
            license.Name = args[1];
            license.Email = args[2];
            license.IssueDate = DateTime.Parse(args[3]);
            license.Duration = TimeSpan.FromDays(double.Parse(args[4]));
            license.Computers = int.Parse(args[5]);
            license.Sign(rsa.ExportParameters(true));

            Console.Out.WriteLine(license.ToString());

            return 0;
        }