|
Infralution Support Support groups for Infralution products
|
View previous topic :: View next topic |
Author |
Message |
Guest Guest
|
Posted: Thu Aug 31, 2006 8:20 pm Post subject: Quick tutorial on how to generate and validate a custom key |
|
|
Hi,
I wonder if it would be possible for you to post a short description on how to generate a key based on customer name and email followed by how to validate the generated key.
What I want to do is to make it possible for my customers to get a key when they buy my product via my ASP.net webpage. The key is generated on the fly based on their name and email.
When they have installed my software they are prompted to enter their name, email and license key. The license key is then valid only if they have entered correct name and email.
Now, I have created a simple windows application that simulates a user entering their details in a form. I have a name and an email textbox, a button to generate the key and finally a button to validate the key.
Code: | using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Infralution.Licensing;
namespace LicenseDesktop
{
public partial class MainClient : Form
{
public MainClient()
{
InitializeComponent();
}
private void _btnGenerateKey_Click(object sender, EventArgs e)
{
_txtStatus.Text = "Key is being generated";
// Do something with the name (_txtName.Text) and email (_txtEmail.Text)
// together with the key parameters to generate a key.
}
private void _btnValidateKey_Click(object sender, EventArgs e)
{
_txtStatus.Text = "Key is being validated";
// Do something with the _txtKey.Text in order to match it with name and
// email and all the rest.
}
}
} |
My problem is that I don't know how to fill in the gaps to make it all work.
It would save me alot of time if you could help me.
Thank you! |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Aug 31, 2006 11:10 pm Post subject: |
|
|
The CustomerGenerator and Custom Licensed App sample projects do this. The code below also shows how:
Code: | using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Infralution.Licensing;
namespace LicenseDesktop
{
public partial class MainClient : Form
{
public MainClient()
{
InitializeComponent();
}
const string LICENSE_PARAMETERS =
@"<LicenseParameters>
<RSAKeyValue>
<Modulus>rzRJ6dZ4ZTJ8/EzFtq2XIaik7QBSc24b8i8KJrPaxXGiCMDFcj8JtEFePa1SYX1W3cQoiwvCAF/MYmkXto74WdApYzILel+bOHSaUXTImrxpPtykNhPD7fF3PEXxrLRrTjUWQyEX5+XSaNPstmbDJw/Zg83mraCfmGeLcsiEypM=</Modulus>
<Exponent>AQAB</Exponent>
</RSAKeyValue>
<DesignSignature>GJYsK2rQE7uj539+QCyJ3Z2GyrNEZQNxruxOQR6P2jo+Ze3Ev5Kgbf3N33RaLf7oEUsZNF4Gv7w5UFgYcdHzCphqznt4vcR++u9tb0sC5m6hf26538GXhkNodyVR9FDcv1AX4+PaM/kY+Z8mrMMmC148lYPpCHypXvgjOmDd9oQ=</DesignSignature>
<RuntimeSignature>coZIUnOTaRZCIa67HBMM6/xbkQNYS+l4ROeLmzn7SqRamBwP7cbfOEAsxlFV2roKlY6oz1B91/PYcTVPLfWahwjHaiAaLjKAosXK41yZOozu0vRWpv4H9ERiEli0pYX0M8fMBIkvSDT6n9X9T/6U4ujyefv8b4IxbYsB3zsjjx0=</RuntimeSignature>
<KeyStrength>7</KeyStrength>
</LicenseParameters>";
private EncryptedLicenseProvider _licenseProvider = new EncryptedLicenseProvider();
private string _licenseKey;
private void _btnGenerateKey_Click(object sender, EventArgs e)
{
String customerInfo = _txtEmail.Text.Trim() + _txtName.Text.Trim();
// we could include the total customer info - but that will result in a very long key
// instead just include a checksum on the info
//
String productInfo = EncryptedLicense.Checksum(customerInfo);
_licenseKey = _licenseProvider.GenerateKey(7, "TEST", productInfo, 0);
}
private void _btnValidateKey_Click(object sender, EventArgs e)
{
EncryptedLicenseProvider.SetParameters(LICENSE_PARAMETERS);
// extract the license from the key
//
EncryptedLicense license = _licenseProvider.ValidateLicenseKey(_licenseKey);
if (license != null)
{
String customerInfo = _txtEmail.Text.Trim() + _txtName.Text.Trim();
String productInfo = EncryptedLicense.Checksum(customerInfo);
// verify that the data entered matches that in the key
//
if (license.ProductInfo == productInfo)
{
MessageBox.Show("Valid License Details");
}
else
{
MessageBox.Show("Customer Info does not match License");
}
}
else
{
MessageBox.Show("Invalid License Key");
}
}
}
} |
_________________ Infralution Support |
|
Back to top |
|
|
Guest Guest
|
Posted: Fri Sep 01, 2006 3:55 pm Post subject: |
|
|
Thank you for the quick reply
It was very useful to me to get this example. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|