/// <summary> /// Test a generic key generation with 2 parameters 5-5-5-5-5 /// </summary> [Test] public void Test10_Gen3ParB16Bit55555() { int lopcnt; try { GenerateKey gkey; string finalkey; for (lopcnt = 1; lopcnt < 30; lopcnt++) { gkey = new GenerateKey(); gkey.LicenseTemplate = "vvvvppppxxxxxxxxxxxx-wwwwwwwwxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx"; gkey.MaxTokens = 3; gkey.AddToken(0, "v", LicenseKey.GenerateKey.TokenTypes.NUMBER, "1"); gkey.AddToken(1, "p", LicenseKey.GenerateKey.TokenTypes.NUMBER, "2"); gkey.AddToken(2, "w", LicenseKey.GenerateKey.TokenTypes.CHARACTER, "QR"); gkey.UseBase10 = false; gkey.UseBytes = false; gkey.CreateKey(); finalkey = gkey.GetLicenseKey(); if ((finalkey.Length - 4) != ((gkey.LicenseTemplate.Length - 4) / 4)) { throw new Exception("Keys are not the same length"); } } } catch (Exception e) { Assert.AreEqual(66, 1, "UnExpected Failure. " + e.Message); } }
/// <summary> /// Test a generic key generation with 5 parameters 5-5-5-5-5 /// </summary> [Test] public void Test15_Gen5DisParB16Bit55555() { int lopcnt; try { GenerateKey gkey; string finalkey; string result; for (lopcnt = 1; lopcnt < 30; lopcnt++) { gkey = new GenerateKey(); gkey.LicenseTemplate = "vvvvvvvvppppxxxxxxxx-wwwwxxxxxxxxxxxxxxxx-ssssssssxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxrrrr"; gkey.MaxTokens = 5; gkey.AddToken(0, "v", LicenseKey.GenerateKey.TokenTypes.NUMBER, "14"); gkey.AddToken(1, "p", LicenseKey.GenerateKey.TokenTypes.NUMBER, "2"); gkey.AddToken(2, "w", LicenseKey.GenerateKey.TokenTypes.NUMBER, "6"); gkey.AddToken(3, "s", LicenseKey.GenerateKey.TokenTypes.NUMBER, "BC"); gkey.AddToken(4, "r", LicenseKey.GenerateKey.TokenTypes.NUMBER, "5"); gkey.UseBase10 = false; gkey.UseBytes = false; gkey.CreateKey(); finalkey = gkey.GetLicenseKey(); if ((finalkey.Length - 4) != ((gkey.LicenseTemplate.Length - 4) / 4)) { throw new Exception("Keys are not the same length"); } result = gkey.DisassembleKey("v"); if (result != "14") { throw new Exception("The first tokens are not equal"); } result = gkey.DisassembleKey("p"); if (result != "2") { throw new Exception("The second tokens are not equal"); } result = gkey.DisassembleKey("w"); if (result != "6") { throw new Exception("The third tokens are not equal"); } result = gkey.DisassembleKey("s"); if (result != "BC") { throw new Exception("The third tokens are not equal"); } result = gkey.DisassembleKey("r"); if (result != "5") { throw new Exception("The third tokens are not equal"); } } } catch (Exception e) { Assert.AreEqual(66, 1, "UnExpected Failure. " + e.Message); } }
/// <summary> /// Test a generic key generation with no parameters 5-5-5-5-5 /// </summary> [Test] public void Test06_Gen2ParB16Byt55555() { int lopcnt; try { GenerateKey gkey; string finalkey; for (lopcnt = 1; lopcnt < 30; lopcnt++) { gkey = new GenerateKey(); gkey.LicenseTemplate = "vvxxx-xxxxx-ppxxx-xxxxx-xxxxx"; gkey.MaxTokens = 2; gkey.AddToken(0, "v", LicenseKey.GenerateKey.TokenTypes.NUMBER, "12"); gkey.AddToken(1, "p", LicenseKey.GenerateKey.TokenTypes.NUMBER, "23"); gkey.UseBase10 = false; gkey.UseBytes = true; gkey.CreateKey(); finalkey = gkey.GetLicenseKey(); if (finalkey.Length != gkey.LicenseTemplate.Length) { throw new Exception("Keys are not the same length"); } } } catch (Exception e) { Assert.AreEqual(66, 1, "UnExpected Failure. " + e.Message); } }
private void button1_Click(object sender, EventArgs e) { GenerateKey gkey; //gkey = new GenerateKey(); //gkey.LicenseTemplate = "xxxxxxxx-xxxx-xxxxxxxx-xxxx"; //gkey.MaxTokens = 0; //gkey.UseBase10 = true; //gkey.UseBytes = true; //gkey.CreateKey(); gkey = new GenerateKey(); gkey.LicenseTemplate = "vvvvvvvvppppxxxxxxxx-wwwwxxxxxxxxxxxxxxxx-ssssssssxxxxxxxxxxxx-xxxxxxxxxxxxcccccccc-xxxxxxxxxxxxxxxxrrrr"; gkey.MaxTokens = 5; gkey.ChecksumAlgorithm = Checksum.ChecksumType.Type1; gkey.AddToken(0, "v", LicenseKey.GenerateKey.TokenTypes.NUMBER, "34"); gkey.AddToken(1, "p", LicenseKey.GenerateKey.TokenTypes.NUMBER, "6"); gkey.AddToken(2, "w", LicenseKey.GenerateKey.TokenTypes.NUMBER, "8"); gkey.AddToken(3, "s", LicenseKey.GenerateKey.TokenTypes.CHARACTER, "ab"); gkey.AddToken(4, "r", LicenseKey.GenerateKey.TokenTypes.NUMBER, "3"); gkey.UseBase10 = false; gkey.UseBytes = false; gkey.CreateKey(); MessageBox.Show(gkey.GetLicenseKey()); }
/// <summary> /// This method will gives the license key /// </summary> /// <returns>License key string</returns> public string GetlicenseKey() { var keygeneration = new GenerateKey(); keygeneration.LicenseTemplate = "vvvvppppxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx" + "-xxxxxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxx"; keygeneration.MaxTokens = 2; keygeneration.AddToken(0, "v", GenerateKey.TokenTypes.NUMBER, "1"); keygeneration.AddToken(1, "p", GenerateKey.TokenTypes.NUMBER, "2"); keygeneration.UseBase10 = false; keygeneration.UseBytes = false; keygeneration.CreateKey(); return(keygeneration.GetLicenseKey()); }
/// <summary> /// Test a generic key generation with no parameters 5-5-5-5-5 /// </summary> [Test] public void Test13_GenDis3ParB16Byt55555() { int lopcnt; try { GenerateKey gkey; string finalkey; string result; for (lopcnt = 1; lopcnt < 30; lopcnt++) { gkey = new GenerateKey(); gkey.LicenseTemplate = "vvxxx-xxxxx-ppxxx-ssxxx-xxxxx"; gkey.MaxTokens = 3; gkey.AddToken(0, "v", LicenseKey.GenerateKey.TokenTypes.NUMBER, "12"); gkey.AddToken(1, "p", LicenseKey.GenerateKey.TokenTypes.NUMBER, "23"); gkey.AddToken(2, "s", LicenseKey.GenerateKey.TokenTypes.CHARACTER, "GH"); gkey.UseBase10 = false; gkey.UseBytes = true; gkey.CreateKey(); finalkey = gkey.GetLicenseKey(); if (finalkey.Length != gkey.LicenseTemplate.Length) { throw new Exception("Keys are not the same length"); } result = gkey.DisassembleKey("v"); if (result != "12") { throw new Exception("The first tokens are not equal"); } result = gkey.DisassembleKey("p"); if (result != "23") { throw new Exception("The second tokens are not equal"); } result = gkey.DisassembleKey("s"); if (result != "GH") { throw new Exception("The third tokens are not equal"); } } } catch (Exception e) { Assert.AreEqual(66, 1, "UnExpected Failure. " + e.Message); } }
private void btnDecode_Click(object sender, System.EventArgs e) { GenerateKey gkey; int numtokens; int lop; string result; string tokenvalue = ""; if (txtKeyInput.Text.Length == 0) { MessageBox.Show("Enter a Key Template", "Layout"); txtKeyInput.Focus(); return; } gkey = new GenerateKey(); // set the base type. if (rdobtn10.Checked) { // use base 10 gkey.UseBase10 = true; } else { // use base 16 gkey.UseBase10 = false; } // set the token type. if (rdobtnBytes.Checked) { // use bytes gkey.UseBytes = true; } else { // use bits gkey.UseBytes = false; } // set the Checksum type. if (rdoBtnChksum1.Checked) { // use Algorithm 1 gkey.ChecksumAlgorithm = Checksum.ChecksumType.Type1; } else { // use Algorithm 2 gkey.ChecksumAlgorithm = Checksum.ChecksumType.Type2; } // Set the number of tokens. numtokens = listView1.Items.Count; if (numtokens > 0) { gkey.MaxTokens = numtokens; lop = 0; foreach (ListViewItem item in listView1.Items) { GenerateKey.TokenTypes ttypes; string tempstr; tempstr = item.SubItems[1].Text; ttypes = GenerateKey.TokenTypes.NUMBER; // default junk switch (tempstr) { case "numeric": case "Numeric": ttypes = GenerateKey.TokenTypes.NUMBER; break; case "character": case "Character": ttypes = GenerateKey.TokenTypes.CHARACTER; break; default: MessageBox.Show("Illegal Token type in switch", "Generatekey"); break; } try { gkey.AddToken(lop, item.SubItems[0].Text, ttypes, item.SubItems[2].Text); } catch (Exception ex) { MessageBox.Show("Error is " + ex.InnerException); btnAdd.Focus(); return; } lop++; } gkey.LicenseTemplate = txtKeyInput.Text; // first create the key try { gkey.CreateKey(); } catch (Exception ex) { MessageBox.Show("Error exception is: " + ex.Message); return; } txtLicKey.Text = gkey.GetLicenseKey(); foreach (ListViewItem item in listView1.Items) { tokenvalue = item.SubItems[0].Text; // now decode the key try { result = gkey.DisassembleKey(tokenvalue); } catch (Exception ex) { MessageBox.Show("Error exception is: " + ex.Message); return; } item.SubItems[3].Text = result; } } }