public void CreateLicenseFile(LicDto dto, string fileName) { var ms = new MemoryStream(); new XmlSerializer(typeof(LicDto)).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(PrivateKey); // 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); // Sign the XML document. SignXml(xmlDoc, rsaKey); // Save the document. xmlDoc.Save(fileName); }
static void Main(string[] args) { if (args.Any(a => a == "--generate")) { GenerateNewKeyPair(); } var dto = new LicDto() { ValidUntil = DateTime.Now.AddDays(7) }; var fileName = string.Join("", DateTime.Now.ToString().Where(c => char.IsDigit(c))); new LicenceGenerator().CreateLicenseFile(dto, fileName + ".gh_licence"); }