Example #1
0
        public IServerLicense Generate(IPrivateCryptoKey privateKey, LicenseCriteria licenseCriteria, string elementKey = null)
        {
            var licenseDocument = this.CreateLicenseDocument(licenseCriteria);

            if (!string.IsNullOrEmpty(elementKey))
            {
                var hashSha256 = new SHA256CryptoServiceProvider();
                var keyArray   = hashSha256.ComputeHash(Encoding.UTF8.GetBytes(elementKey));

                //Always release the resources and flush data
                // of the Cryptographic service provide. Best Practice
                hashSha256.Clear();

                // Create a new TripleDES key.
                var rijndaelkey = Rijndael.Create();

                rijndaelkey.Key = keyArray;

                try
                {
                    foreach (var metaData in licenseCriteria.MetaData)
                    {
                        // Encrypt the metadata element.
                        Encrypt(licenseDocument, metaData.Key, rijndaelkey);
                    }

                    // Display the encrypted XML to the console.
                    //Console.WriteLine("Encrypted XML:");
                    //Console.WriteLine();
                    //Console.WriteLine(licenseDocument.OuterXml);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                finally
                {
                    // Clear the TripleDES key.
                    rijndaelkey.Clear();
                }
            }

            var signature = LicenseSignatureGenerator.GenerateSignature(licenseDocument, privateKey);

            licenseDocument.FirstChild.AppendChild(licenseDocument.ImportNode(signature, true));

            return(new ServerLicense
            {
                Content = licenseDocument,
                Criteria = licenseCriteria,
                PrivateKey = privateKey,
                PublicKey = privateKey.ExtractPublicKey()
            });
        }
Example #2
0
        public IServerLicense Generate(IPrivateCryptoKey privateKey, LicenseCriteria licenseCriteria)
        {
            var licenseDocument = this.CreateLicenseDocument(licenseCriteria);

            var signature = LicenseSignatureGenerator.GenerateSignature(licenseDocument, privateKey);

            licenseDocument.FirstChild.AppendChild(licenseDocument.ImportNode(signature, true));

            return(new ServerLicense
            {
                Content = licenseDocument,
                Criteria = licenseCriteria,
                PrivateKey = privateKey,
                PublicKey = privateKey.ExtractPublicKey()
            });
        }