public void DecryptString_MatchEncryptString_ReturnTrue() { Encryption.Encryption aEncryption = new Encryption.Encryption(); var en = aEncryption.EncryptString("kamol"); var dec = aEncryption.DecryptString(en); Assert.AreEqual("kamol", dec); }
public IEncryption GetEncryptionProvider(Encryption.Encryption encryption) { switch (encryption) { case Encryption.Encryption.TripleDES: return(new TripleDESEncryption(this.GetSerializer())); case Encryption.Encryption.BlowFish: return(new BlowFishEncryption(this.GetSerializer())); case Encryption.Encryption.Rijndael: return(new RijndaelEncryption(this.GetSerializer())); default: throw new ArgumentException("encryption"); } }
public ParsedThermostat(Thermostat thermostat) { this.thermostat = thermostat; this.encryption = new Encryption.Encryption(thermostat.SecretKey); batteryLevelBytes = Conversion.HexStringToByteArray(thermostat.BatteryLevel); Trace.Assert(batteryLevelBytes.Length == 1, "Expected battery level to be 1 byte, got " + batteryLevelBytes.Length); deviceNameBytes = encryption.Decrypt(thermostat.Name); settingsBytes = encryption.Decrypt(thermostat.Settings); Trace.Assert(settingsBytes.Length == 16, "Expected settings to be 16 bytes, got " + settingsBytes.Length); temperatureBytes = encryption.Decrypt(thermostat.Temperature); Trace.Assert(temperatureBytes.Length == 8, "Expected temperature to be 8 bytes, got " + temperatureBytes.Length); schedule1Bytes = encryption.Decrypt(thermostat.Schedule1); Trace.Assert(schedule1Bytes.Length == 20, "Expected schedule1 to be 20 bytes, got " + schedule1Bytes.Length); schedule2Bytes = encryption.Decrypt(thermostat.Schedule2); Trace.Assert(schedule2Bytes.Length == 12, "Expected schedule2 to be 12 bytes, got " + schedule2Bytes.Length); schedule3Bytes = encryption.Decrypt(thermostat.Schedule3); Trace.Assert(schedule3Bytes.Length == 12, "Expected schedule3 to be 12 bytes, got " + schedule3Bytes.Length); }
public JsonResult getKeyVal() { IEnumerable<string> headerValues = Request.Headers.GetValues("Authorization"); String guid = headerValues.FirstOrDefault(); guid = guid.Replace("/", ""); CPSession retVal = TokenManager.getSessionInfo(guid); string userName = retVal.getAttributeValue("userName"); var _db = new ZestorkContainer(); var UserInfo = _db.Users.SingleOrDefault(x => x.Username == userName); Encryption.Encryption EncryptionObj = new Encryption.Encryption(); string cipherKey = EncryptionObj.getEncryptionKey(UserInfo.Password, UserInfo.guid); return Json(new { code = "200", key = cipherKey }, JsonRequestBehavior.AllowGet); }
public JsonResult isValidToken(string id) { var _db = new ZestorkContainer(); string username = Request.QueryString["username"].ToString(); username = username.Split('/')[0]; string password = string.Empty; string key = Request.QueryString["key"].ToString(); key = key.Replace(' ', '+'); if (TokenManager.isValidSession(id)) { CPSession retVal = TokenManager.getSessionInfo(id); string type = retVal.getAttributeValue("type"); if(type=="client") return Json(new { isValid = true, url = "http://" + Request.Url.Authority + "/Client" }, JsonRequestBehavior.AllowGet); else return Json(new { isValid = true, url = "http://" + Request.Url.Authority + "/secure"+type+"Clientcompare"+type=="client" }, JsonRequestBehavior.AllowGet); } else { Users user = _db.Users.SingleOrDefault(x => x.Username == username); if (user != null && user.KeepMeSignedIn != null) { if (user.KeepMeSignedIn == "true") { Encryption.Encryption EncryptionObj = new Encryption.Encryption(); password = EncryptionObj.getDecryptionValue(key, user.guid); if (password == user.Password) { CPSession session = new CPSession(); session.addAttribute("userName", user.Username); session.addAttribute("type", AccountControllerMethods.getUserType(user.Username)); bool isPersistent = false; // as of now we have only 1 type of login session.setID(id); TokenManager.CreateSession(session, isPersistent); return Json(new { isValid = true, url = "http://" + Request.Url.Authority + "/secure" }, JsonRequestBehavior.AllowGet); } return Json(new { isValid = false, url = "http://" + Request.Url.Authority + "/secure" }, JsonRequestBehavior.AllowGet); } } return Json(new { isValid = false, url = "http://" + Request.Url.Authority + "/secure" }, JsonRequestBehavior.AllowGet); } }