private void ButtonGeneruj_Click(object sender, EventArgs e) { MyLicense licencja = new MyLicense { LicenseOwner = textBoxOwner.Text, CreateDateTime = DateTime.Now, LicenseNumber = textBoxLicenseNumber.Text, LicenseEnd = new DateTime(dateTimePickerKoniec.Value.Year, dateTimePickerKoniec.Value.Month, dateTimePickerKoniec.Value.Day, 23, 59, 59), Atr1 = textBoxAtr1.Text }; using (MemoryStream ms = new MemoryStream()) using (Bitmap bitmap = new Bitmap(pictureBoxLogo.Image)) { bitmap.Save(ms, ImageFormat.Png); licencja.LogoOwner = Convert.ToBase64String(ms.GetBuffer()); } if (radioButtonSingle.Checked) { if (LicenseHandler.ValidateUidFormat(textBoxUid.Text.Trim())) { licencja.Type = LicenseTypes.Single; licencja.Uid = textBoxUid.Text.Trim(); } else { MessageBox.Show(@"Błędny lub pusty identyfikator licencji", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } else if (radioButtonVolume.Checked) { licencja.Type = LicenseTypes.Volume; licencja.Uid = string.Empty; } byte[] certPrivateKeyData; Assembly assembly = Assembly.GetExecutingAssembly(); using (MemoryStream memoryStream = new MemoryStream()) { assembly.GetManifestResourceStream("LicenseGenerator.LicenseSign.pfx")?.CopyTo(memoryStream); certPrivateKeyData = memoryStream.ToArray(); } textBoxLicencja.Text = LicenseHandler.GenerateLicense(licencja, certPrivateKeyData, _certPwd); }
private void ButtonReadLicense_Click(object sender, EventArgs e) { byte[] certPublicKeyData; Assembly assembly = Assembly.GetExecutingAssembly(); using (MemoryStream memoryStream = new MemoryStream()) { assembly.GetManifestResourceStream("LicenseGenerator.LicenseVerify.cer")?.CopyTo(memoryStream); certPublicKeyData = memoryStream.ToArray(); } MyLicense license = (MyLicense)LicenseHandler.ReadLicense(typeof(MyLicense), textBoxLicencja.Text, certPublicKeyData, out LicenseStatus status, out string msg); switch (status) { case LicenseStatus.Undefined: MessageBox.Show(@"By używać tej aplikacji musisz posiadać ważną licencję", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); break; case LicenseStatus.Invalid: case LicenseStatus.Cracked: MessageBox.Show(msg, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); break; case LicenseStatus.Valid: case LicenseStatus.Expired: textBoxUid.Text = license.Uid; textBoxLicenseNumber.Text = license.LicenseNumber; textBoxOwner.Text = license.LicenseOwner.Replace("\n", Environment.NewLine); dateTimePickerKoniec.Value = license.LicenseEnd; using (MemoryStream ms = new MemoryStream(Convert.FromBase64String(license.LogoOwner))) { Bitmap bm = new Bitmap(ms); pictureBoxLogo.Image = bm; } break; default: throw new ArgumentOutOfRangeException(); } }
private void ButtonGeneruj_Click(object sender, EventArgs e) { MyLicense licencja = new MyLicense { LicenseOwner = textBoxOwner.Text, CreateDateTime = DateTime.Now, LicenseNumber = textBoxLicenseNumber.Text, LicenseEnd = new DateTime(dateTimePickerKoniec.Value.Year, dateTimePickerKoniec.Value.Month, dateTimePickerKoniec.Value.Day, 23, 59, 59) }; using (MemoryStream ms = new MemoryStream()) using (Bitmap bitmap = new Bitmap(_logoPath)) { bitmap.Save(ms, ImageFormat.Png); licencja.LogoOwner = Convert.ToBase64String(ms.GetBuffer()); } if (radioButtonSingle.Checked) { if (LicenseHandler.ValidateUidFormat(textBoxUid.Text.Trim())) { licencja.Type = LicenseTypes.Single; licencja.Uid = textBoxUid.Text.Trim(); } else { MessageBox.Show(@"Błędny lub pusty identyfikator licencji", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } else if (radioButtonVolume.Checked) { licencja.Type = LicenseTypes.Volume; licencja.Uid = string.Empty; } textBoxLicencja.Text = LicenseHandler.GenerateLicense(licencja, _certPrivateKeyData, _certPwd); }