1. Step: Create PKV Keys
Creating some Licence is a bit more complex than creating a product key. At first, if not done, you have to create the Partial Key Verification (PKV) public and private keys. The private key is used to create product keys and the public to validate those.
You can either create thoses keys through the gui (Unity->Window->LicenceMe Settings):
Or through code:
1 2 3 4 5 6 7 |
FileStoring serverPkvStoring = new FileStoring(Application.dataPath + "/OPS/LicenceMe/Editor/PkvKey/PrivateKey.xml"); FileStoring clientPkvStoring = new FileStoring(Application.dataPath + "/OPS/LicenceMe/Resources/OPS/LicenceMe/PkvKey/PublicKey.xml"); int subKeyLength = 4; OPS.LicenceMe.Server.ServerKeyManager.CreateNewPkvSubKeys(subKeyLength, serverPkvStoring, clientPkvStoring); |
2. Step: Create RSA Keys
The Partial Key Verification is used to create user individuell product keys. The next step is to add those product keys some complex condition. To do this LicenceMe uses RSA.
So you have to create the public and private RSA keys. Either through the gui:
Or through code:
1 2 3 4 5 |
String privateFullPath = Application.dataPath + "/OPS/LicenceMe/Editor/RsaKey/PrivateKey.xml"; String publicFullPath = Application.dataPath + "/OPS/LicenceMe/Resources/OPS/LicenceMe/RsaKey/PublicKey.xml"; OPS.LicenceMe.Rsa.RsaHelper.GenerateNewKeys(privateFullPath, publicFullPath); |
3. Step: Create a licence
The licence creation uses the created private keys to create some new licence.
You can either create a licence through the gui:
Or through code (Example: Device depended licence):
1 2 3 4 5 6 7 |
Storing.FileStoring serverPkvStoring = new FileStoring(Application.dataPath + "/OPS/LicenceMe/Editor/PkvKey/PrivateKey.xml"); Storing.FileStoring serverRsaStoring = new FileStoring(Application.dataPath + "/OPS/LicenceMe/Editor/RsaKey/PrivateKey.xml"); String userDeviceLicence = "...."; /*Receive through the user. Use for example OPS.LicenceMe.Helper.DeviceHelper.GetDeviceId(); to receive a unique device id on the client device.*/ OPS.LicenceMe.Licence.DeviceLicenceCondition deviceCondition = new OPS.LicenceMe.Licence.DeviceLicenceCondition(userDeviceLicence); String var_CreatedLicence = OPS.LicenceMe.Server.ServerLicenceManager.CreateLicenceKey(serverPkvStoring, serverRsaStoring, deviceCondition); |
4. Step: Validate a licence
The licence validation uses the public keys for validation.
Again this can be done through the gui.
Or more recommended through code:
1 2 3 4 5 6 7 8 9 10 11 12 |
Storing.ResourcesStoring clientPkvStoring = new ResourcesStoring("OPS/LicenceMe/PkvKey/PublicKey"); Storing.ResourcesStoring clientRsaStoring = new ResourcesStoring("OPS/LicenceMe/RsaKey/PublicKey"); String userDeviceLicence = "...."; //Load from some location. String userDeviceId = "...."; //Load from some location. //Or get local //userDeviceId = OPS.LicenceMe.Helper.DeviceHelper.GetDeviceId(); OPS.LicenceMe.Licence.DeviceLicenceCondition deviceCondition = new OPS.LicenceMe.Licence.DeviceLicenceCondition(userDeviceId); bool valid = OPS.LicenceMe.Client.ClientLicenceManager.ValidateLicence(clientPkvStoring, clientRsaStoring, userDeviceLicence, deviceCondition); |
Optional: 5. Step: Custom conditions
LicenceMe contains three included licence conditions (Trial/DeviceId/Name). You can either extend those or create custom conditions.
To do so, inherit the class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
namespace OPS.LicenceMe.Licence { /// <summary> /// This abstract class makes it easier to create and validate custom licence conditions. /// </summary> public abstract class ALicenceCondition { /// <summary> /// Server side: Use this method to create a licence condition. /// </summary> /// <returns></returns> public abstract String CreateCondition(); /// <summary> /// Client side: Use this method to validate a condition created server side through 'CreateCondition'. /// </summary> /// <param name="_Condition"></param> /// <returns></returns> public abstract bool ValidateCondition(String _Condition); } } |