/// <summary> /// Initializes a new instance of a CategoryNode object. /// </summary> /// <param name="licenseRow"></param> public License(IExplorerItem parent, DataSet.LicenseRow licenseRow) { // Validate the parameters. if (licenseRow == null) { throw new ArgumentNullException("licenseRow"); } // Extract the values from the record. base.Name = licenseRow.SerialNumber.ToString(); base.Parent = parent; // This will locat and disassemble the folder icon and give us the basic image sizes supported by the application framework. Uri uri = new Uri("/Teraque.DataModel;component/Resources/License.ico", UriKind.Relative); Dictionary <ImageSize, ImageSource> images = ImageHelper.DecodeIcon(uri); base.SmallImageSource = images[ImageSize.Small]; base.MediumImageSource = images[ImageSize.Medium]; base.LargeImageSource = images[ImageSize.Large]; base.ExtraLargeImageSource = images[ImageSize.ExtraLarge]; }
internal static void GenerateLicense(LicenseInfo licenseInfo, String fileName) { if (licenseInfo == null) { throw new ArgumentNullException("licenseInfo"); } DataSet.ProductRow productRow = DataModel.Product.FindByProductId(licenseInfo.ProductId); DataSet.CustomerRow customerRow = DataModel.Customer.FindByCustomerId(licenseInfo.CustomerId); // Generate a new license. DataSet.LicenseRow licenseRow = DataModel.License.AddLicenseRow( licenseInfo.DateCreated, customerRow, Guid.NewGuid(), licenseInfo.LicenseType, productRow); DataModel.LicenseTableAdapter.Update(DataModel.License); // Generate the payload from the license type, the product id, the serial number and the current date. Byte[] licenseType = BitConverter.GetBytes(licenseRow.LicenseType); Byte[] productIdArray = licenseRow.ProductId.ToByteArray(); Byte[] serialNumberArray = BitConverter.GetBytes(licenseRow.SerialNumber); Byte[] dateCreatedArray = BitConverter.GetBytes(licenseRow.DateCreated.ToBinary()); Byte[] payload = new Byte[licenseType.Length + productIdArray.Length + serialNumberArray.Length + dateCreatedArray.Length]; Array.Copy(licenseType, payload, licenseType.Length); Array.Copy(productIdArray, 0, payload, licenseType.Length, productIdArray.Length); Array.Copy(serialNumberArray, 0, payload, licenseType.Length + productIdArray.Length, serialNumberArray.Length); Array.Copy(dateCreatedArray, 0, payload, licenseType.Length + productIdArray.Length + serialNumberArray.Length, dateCreatedArray.Length); RSAParameters rsaParameters = new RSAParameters(); rsaParameters.D = LicenseManager.privateKeyD; rsaParameters.DP = LicenseManager.privateKeyDp; rsaParameters.DQ = LicenseManager.privateKeyDq; rsaParameters.Exponent = LicenseManager.publicKeyExponent; rsaParameters.InverseQ = LicenseManager.privateKeyInverseQ; rsaParameters.Modulus = LicenseManager.publicKeyModulus; rsaParameters.P = LicenseManager.privateKeyP; rsaParameters.Q = LicenseManager.privateKeyQ; RSACryptoServiceProvider rsaCryptoServiceProvider = new RSACryptoServiceProvider(); rsaCryptoServiceProvider.ImportParameters(rsaParameters); SHA1CryptoServiceProvider sha1CryptoServiceProvider = new SHA1CryptoServiceProvider(); Byte[] signature = rsaCryptoServiceProvider.SignData(payload, sha1CryptoServiceProvider); Byte[] signedPayload = new Byte[payload.Length + signature.Length]; Array.Copy(payload, signedPayload, payload.Length); Array.Copy(signature, 0, signedPayload, payload.Length, signature.Length); Byte[] publicKey = new Byte[LicenseManager.publicKeyExponent.Length + LicenseManager.publicKeyModulus.Length]; Array.Copy(LicenseManager.publicKeyExponent, publicKey, LicenseManager.publicKeyExponent.Length); Array.Copy(LicenseManager.publicKeyModulus, 0, publicKey, LicenseManager.publicKeyExponent.Length, LicenseManager.publicKeyModulus.Length); Byte[] licenseKey = new Byte[publicKey.Length + signedPayload.Length]; Array.Copy(publicKey, licenseKey, publicKey.Length); Array.Copy(signedPayload, 0, licenseKey, publicKey.Length, signedPayload.Length); using (StreamWriter streamWriter = new StreamWriter(fileName)) streamWriter.WriteLine(Convert.ToBase64String(licenseKey)); }