private static void CreateProject() { //AsymmetricEncryption.GenerateRegisterFile("yazhi.pang", "autox"); var fileContent = File.ReadAllText("yazhi.pang.pem"); var forSake = XElement.Parse(fileContent); var projectName = forSake.GetAttributeValue("ProjectName"); if (MongoDBManager.GetInstance().IsProjectExisted(projectName)) { Console.WriteLine("Project already existed, continue?(y/n):"); if (!Console.ReadKey().KeyChar.Equals('y')) { return; } } MongoDBManager.GetInstance().SetProject(projectName); var root = forSake.Element("Root"); var publicAndPrivateKey = root.GetAttributeValue("PublicAndPrivateKey"); var secret = root.GetAttributeValue("Secret"); var decrypted = AsymmetricEncryption.DecryptText(secret, 2048, publicAndPrivateKey); var userName = root.GetAttributeValue("UserName"); foreach (XElement descendant in forSake.Descendants()) { DBFactory.GetData().Save(descendant); } }
private bool CheckKey() { using (var config = new PosBusiness.Config()) { const int keySize = 1024; var keyDate = config.KeyDate(); var publicKey = config.PublicKey(); var decrypted = AsymmetricEncryption.DecryptText(config.KeyDate(), keySize, config.PublicKey()); var product = decrypted.Split('|')[0]; var date = decrypted.Split('|')[1]; var d = int.Parse(date.Split('/')[0]); var m = int.Parse(date.Split('/')[1]); var a = int.Parse(date.Split('/')[2]); var dt = new DateTime(a, m, d); if (DateTime.Now > dt) { this.Alert("La clave del producto caduco, obtenga una nueva clave de producto comunicándose con soporte técnico Scripts MX", eForm.TypeError.Error); return(false); } return(true); } }
private void btnDecrypt_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(textBox2.Text)) { textBox3.Text = AsymmetricEncryption.DecryptText(textBox2.Text, keySize, publicAndPrivateKey); } }
private static void ForTempSave(string userName) { const int keySize = 2048; string publicAndPrivateKey; string publicKey; var root = new XElement("Root"); root.SetAttributeValue(Constants._ID, Guid.NewGuid().ToString()); AsymmetricEncryption.GenerateKeys(keySize, out publicKey, out publicAndPrivateKey); Console.WriteLine(@"public key:" + publicKey); Console.WriteLine(@"public & private key:" + publicAndPrivateKey); root.SetAttributeValue("PublicKey", publicKey); root.SetAttributeValue("PublicAndPrivateKey", publicAndPrivateKey); var productid = AsymmetricEncryption.GetProductId(); root.SetAttributeValue("ProductId", productid); //string userName = "******"; var text = userName + productid; var encrypted = AsymmetricEncryption.EncryptText(text, keySize, publicKey); Console.WriteLine(@"Encrypted: {0}", encrypted); //send encrypted data to service File.WriteAllText(userName + ".pem", @"UserName: "******" Public Key:" + publicKey + @" Public and Private Key: " + publicAndPrivateKey + @"Secrect: " + encrypted + @" For Test: " + productid); var decrypted = AsymmetricEncryption.DecryptText(encrypted, keySize, publicAndPrivateKey); //service person do below Console.WriteLine(@"Decrypted: {0}", decrypted); // Configuration.Set("UserName", userName); // Configuration.Set("PublicKey", publicKey); // Configuration.SaveSettings(); DBFactory.GetData().Save(root); Console.WriteLine(DBFactory.GetData().Read("a02cf4ad-ba0c-4c69-9f7c-e7d73a8fecad")); }
String Decrypt(String text) { String encrypted = AsymmetricEncryption.DecryptText(text, KEYSIZE, _publicAndPrivateKey); return(encrypted); }
public override void OnInvoke(MethodInterceptionArgs args) { bool?isLicenced = HttpContext.Current.Cache["isLicenced"] as bool?; if (!isLicenced.HasValue) { string licenceKeyPath = HttpContext.Current.Server.MapPath("/") + "Licence.lic"; string licenceKey = GetLicenceKey(licenceKeyPath); // If key is valid var decrypted = AsymmetricEncryption.DecryptText(licenceKey, _keySize, _publicAndPrivateKeyXml); var keys = decrypted.Split('-'); var expireDate = DateTime.FromFileTimeUtc(Convert.ToInt64(keys.Last())); DateTime currentDate; try { currentDate = GetNetworkTime(); } catch { currentDate = DateTime.Now; // Clock Manipulation Control bool isManipulated = DetectClockManipulation(currentDate); if (isManipulated) { throw new UnauthorizedAccessException("System Clock Manipulation Detected!"); } } if (expireDate > currentDate) { var hwId = decrypted.Replace(keys.Last(), string.Empty); string uniqueId = HardwareInfo.GenerateUniqueId() + "-"; // Hardware control if (hwId != uniqueId) { throw new UnauthorizedAccessException("System Change Detected!"); } isLicenced = true; HttpContext.Current.Cache.Insert("isLicenced", isLicenced, new CacheDependency(licenceKeyPath), DateTime.Now.AddDays(1), TimeSpan.Zero); } else { isLicenced = false; } } if (isLicenced.Value) { base.OnInvoke(args); return; } else { throw new UnauthorizedAccessException("Your licence is expired or invalid!"); } }