Exemplo n.º 1
0
    public static List <T> Load <T>(string fileName) where T : class
    {
        Type type = typeof(T);

        if (!type.IsDefined(typeof(System.SerializableAttribute), true))
        {
            Debuger.LogError(type.Name + " doesn't has the SerializableAttribute." +
                             "please add it!");
        }
#if ENCRYPT
        string    encrptName  = Utils.AESEncrypt(fileName);
        TextAsset jsonText    = Resources.Load <TextAsset>("Jsons\\" + encrptName);
        string    decryptJson = Utils.AESDecrypt(jsonText.text);
#else
        string    encrptName  = fileName;
        TextAsset jsonText    = Resources.Load <TextAsset>("Jsons\\" + encrptName);
        string    decryptJson = "";
        try
        {
            decryptJson = jsonText.text;
        }
        catch (NullReferenceException)
        {
            Debug.LogError("Json Read Name Is Null By " + encrptName);
            return(null);
        }
#endif
        return(JsonUtility.FromJson <JsonStructure <T> >(decryptJson).data);
    }
Exemplo n.º 2
0
 public DataTable QueryPatientBy(string recordNo, string inhosTimes)
 {
     try
     {
         string ConnString = Utils.AESDecrypt(ConfigHelper.GetAppStrings("ConntionString"));
         //ConnString = "Data Source=DBSERVER; User Id=mhis; Password=mrd;Provider=MSDAORA;Persist Security Info=True;";
         //string dc = Utils.AESEncrypt(ConnString);
         using (Adapter ada = new Adapter(ConnString))
         {
             return(ada.Query(SqlText.SqlSelectPatient, new object[] { recordNo, inhosTimes }));
         }
     }
     catch
     {
         return(null);
     }
 }
Exemplo n.º 3
0
 private string Decrypt(string encrypt)
 {
     return(Utils.AESDecrypt(encrypt, _symmetricKey));
 }
Exemplo n.º 4
0
 private string Decrypt(string encrypt)
 {
     //return string.Format("convert(nvarchar(100),convert(varbinary(512),{0},1))", encrypt);
     return(Utils.AESDecrypt(encrypt, _symmetricKey));
 }
Exemplo n.º 5
0
        /// <summary>
        /// Extracts the parameters and JSON from the request object and calls the specified HTTP method function.
        /// </summary>
        protected override void Main()
        {
            // Get the session from the cookies (if it exists)
            var sessionId = Request.Cookies["session"]?.Value;

            CurrentSession = sessionId == null ? null : Utils.GetSession(sessionId);

            // Read the inputstream of the request and try to convert it to a JObject
            JObject content;

            try
            {
                // If content length is 0 (no content) then use blank JObject
                if (Request.ContentLength64 == 0)
                {
                    content = new JObject();
                }
                else
                {
                    string body;
                    // If the data isn't a json, expect encoded data
                    if (Request.ContentType != "application/json")
                    {
                        // Send error if the request is missing encryption data
                        if (!Utils.IsRequestEncrypted(Request))
                        {
                            Server.SendError(HttpStatusCode.BadRequest);
                            return;
                        }

                        // Get iv and session from request headers and cookies
                        var iv = Convert.FromBase64String(Request.Headers.Get("Content-IV"));

                        // Get all bytes from the request body
                        using var mem = new MemoryStream();
                        Request.InputStream.CopyTo(mem);
                        mem.Close();

                        // Decrypt the body
                        body = Encoding.UTF8.GetString(Utils.AESDecrypt(CurrentSession, mem.ToArray(), iv));
                    }
                    else
                    {
                        // Read all text from inputstream
                        using var reader = new StreamReader(Request.InputStream, Request.ContentEncoding);
                        body             = reader.ReadToEnd();
                    }
                    content = JObject.Parse(body);
                }
            }
            catch (JsonReaderException)
            {
                // Send BadRequest if it doesn't contain a readable JSON
                Server.SendError(HttpStatusCode.BadRequest);
                return;
            }
            var parameters = SplitQuery(Request);

            // Get the right method from the endpoint using Reflection
            var method = GetType().GetMethod(Request.HttpMethod.ToUpper());

            if (method == null)
            {
                // Send a 501 not implemented if the method does exist
                Server.SendError(HttpStatusCode.NotImplemented);
            }
            else if (method.GetCustomAttribute <RequiresEncryptionAttribute>() != null && !Utils.IsRequestEncrypted(Request))
            {
                // If the method requires encrypted data but the request is unencrypted, send a 400 Bad Request.
                Server.SendError(HttpStatusCode.BadRequest);
            }
            else
            {
                // Check if the endpoint requires login info
                if (GetType().GetCustomAttribute <RequiresLoginAttribute>() != null)
                {
                    // Get the current user from the property
                    if (CurrentUser == null)
                    {
                        // Send a 401 status code if the login data is missing
                        Server.SendError(HttpStatusCode.Unauthorized);
                        return;
                    }
                }
                // Run the requested endpoint method
                method.Invoke(this, new object[] { content, parameters });
            }
        }