Exemplo 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 OfflineKeyValidationWithPeriodicTimeCheck()
        {
            var RSAPublicKey = "<RSAKeyValue><Modulus>sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";

            var keyInfo = new KeyInformation().LoadFromFile("c:\\test\\license2.txt");

            if (keyInfo.HasValidSignature(RSAPublicKey, 3)
                .IsValid())
            {
                // the signature is correct so
                // the program can now launch
                return;
            }
            else
            {
                string key = "";
                if (keyInfo.IsValid())
                {
                    key = keyInfo.Key; // the license key is stored in the activation file.
                }
                else
                {
                    key = "MJAWL-ITPVZ-LKGAN-DLJDN"; // if we are here, ask the user about the key
                }
                var machineCode = SKGL.SKM.getMachineCode(SKGL.SKM.getSHA1);
                keyInfo = SKGL.SKM.KeyActivation("3", "2", "751963", key, machineCode, secure: true, signMid: true, signDate: true);

                if (keyInfo.HasValidSignature(RSAPublicKey).IsValid())
                {
                    // the signature is correct and the key is valid.
                    // save to file.
                    keyInfo.SaveToFile("c:\\test\\license2.txt");

                    // the program can now launch
                    return;
                }
                else
                {
                    // failure. close the program.
                }
            }

            Assert.Fail();
        }