Beispiel #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (License != null)
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    var dto = new LicenseDto();
                    dto.LicenseeName    = textBox2.Text;
                    dto.ValidUntil      = dateTimePicker1.Value;
                    dto.AllowedFeatures = new List <string>();
                    foreach (var val in textBox1.Text.Split(','))
                    {
                        dto.AllowedFeatures.Add(val.Trim());
                    }

                    License.CreateLicenseFile(dto, saveFileDialog1.FileName);

                    MessageBox.Show("Лицензия создана:" + saveFileDialog1.FileName);
                }
            }
        }
        public void CreateLicenseFile(LicenseDto dto, string fileName)
        {
            var ms = new MemoryStream();

            new XmlSerializer(typeof(LicenseDto)).Serialize(ms, dto);

            // Create a new CspParameters object to specify
            // a key container.
            // Create a new RSA signing key and save it in the container.
            RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider();

            rsaKey.FromXmlString(secretKey);

            // Create a new XML document.
            XmlDocument xmlDoc = new XmlDocument();

            // Load an XML file into the XmlDocument object.
            xmlDoc.PreserveWhitespace = true;
            ms.Seek(0, SeekOrigin.Begin);
            xmlDoc.Load(ms);
            SignXml(xmlDoc, rsaKey);
            xmlDoc.Save(fileName);
        }