Esempio n. 1
0
        public void KeyValidation()
        {
            // please add SKGL as a reference (using SKGL)

            /**
             *
             * STEP 1: MACHINE CODE
             * This code should be generated by the client.
             **/

            var machineCode = SKM.getMachineCode(SKM.getSHA1);

            System.Diagnostics.Debug.WriteLine(machineCode);

            /**
             *
             * STEP 2: VALIDATION OF ACTIVATION FILE
             *
             * The code is already pre-configured for you; you only need to specify the file path.
             * You can specify the file path in the string filePath variable below
             *
             * */

            // where the activation file is located
            string filePath     = "c:\\test\\ActivationFile20150020.skm";
            string rsaPublicKey = "<RSAKeyValue><Modulus>sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";

            var keyInfo = new KeyInformation();

            keyInfo = keyInfo.LoadFromFile(filePath, json: true, activationFile: true);

            if (keyInfo.HasValidSignature(rsaPublicKey)
                .IsValid())
            {
                // if we have come so far, the user has a valid activation file
                // where no information has been altered.
                // below this line, please put some logic handle


                if (keyInfo.IsOnRightMachine().IsValid())
                {
                    // if this is not true, the user tries to activate
                    // an activation file that belongs to another computer.
                    // therefore, it's invalid operation and should FAIL.
                    // note, this method assumes you use SHA1 as hashing algorithm
                    // for the machine code.
                }


                // here we can retrieve some useful info
                Console.WriteLine(keyInfo.CreationDate);
                //... etc.
            }
            else
            {
                Assert.Fail();
            }
        }
        public void SaveAndLoadFromFile()
        {
            var ki = new KeyInformation()
            {
                CreationDate   = DateTime.Today,
                ExpirationDate = DateTime.Today.AddDays(3)
            };

            ki.SaveToFile("test123.txt");

            ki = null;

            Assert.IsTrue(ki.LoadFromFile("test123.txt")
                          .HasNotExpired()
                          .IsValid());

            ki.SaveToFile("test123.txt", json: true);

            ki.LoadFromFile("test123.txt", json: true);

            Assert.IsTrue(ki.LoadFromFile("test123.txt")
                          .HasNotExpired()
                          .IsValid());
        }