public IActionResult GetKey(int subId) { var subscription = _subscriptionService.GetById(subId); var ekey = _eKeyService.GetActive(subscription.EnterpriseClientId); try { return(Json(new { c = ResultCode.Success, key = ekey.Key, vector = ekey.IV })); } catch (Exception ex) { _logger.LogError(ex.GetLogText("ekeyapi_GetKey")); return(Json(new { c = ResultCode.GenericException, d = ex.Message })); } }
private string GetDecryptedString(string base64EncryptedValue, Subscription subscription) { var result = ""; try { var ekey = _eKeyService.GetActive(subscription.EnterpriseClientId); var decryptedString = _eKeyService.Decrypt(base64EncryptedValue, ekey.Key, ekey.IV); result = decryptedString; } catch { } return(result); }
public IActionResult Add([FromBody] dynamic value) { try { string svalue = Convert.ToString(value); dynamic UserJsonEntity = JsonConvert.DeserializeObject(svalue); string firstname = UserJsonEntity["fn"]; string lastname = UserJsonEntity["ln"]; string licencekey = UserJsonEntity["lk"]; var seatkey = UserJsonEntity["sk"]; string optionaldata = UserJsonEntity["opt"]; var devicetype = UserJsonEntity["dt"]; var devicemodel = UserJsonEntity["dm"]; //get the enterprise encryption key Subscription subscription = _subscriptionService.GetByLicenceKey(licencekey); if (subscription == null) { return(Json(new { c = ResultCode.UserDataResultCodes.SubscriptionDoesntExist, d = "" })); } EKey eKey = _eKeyService.GetActive(subscription.EnterpriseClientId); if (eKey != null) { _userDataService.Add(new Entity.Model.UserData() { FirstName = GetEncryptedString(firstname, eKey), LastName = GetEncryptedString(lastname, eKey), LicenceKey = licencekey, SeatKey = seatkey, OptionalData = string.IsNullOrEmpty(optionaldata)? null : GetEncryptedString(optionaldata, eKey), DeviceType = devicetype, DeviceModel = devicemodel }); return(Json(new { c = ResultCode.Success, d = true })); } else { return(Json(new { c = ResultCode.UserDataResultCodes.EkeyDoesntExist, d = "" })); } } catch (Exception ex) { _logger.LogError(ex.GetLogText("userdataapi_adduserdata")); return(Json(new { c = ResultCode.GenericException, d = ex.Message })); } }