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()); }
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(); }