public virtual void SaveSecure(string tag, string data, string userId = null)
        {
            if (string.IsNullOrEmpty(data))
            {
                return;
            }

            bool saved = false;

            try {
                string saveFileName = GetFileName(tag, userId);
                SwrveLog.Log("Saving: " + saveFileName, "storage");
                CrossPlatformFile.SaveText(saveFileName, data);
                string signatureFileName = saveFileName + SIGNATURE_SUFFIX;
                string signature         = SwrveHelper.CreateHMACMD5(data, uniqueKey);

                CrossPlatformFile.SaveText(signatureFileName, signature);

                saved = true;
            } catch (Exception e) {
                SwrveLog.LogError(e.ToString(), "storage");
            }

            if (!saved)
            {
                SwrveLog.LogWarning(tag + " not saved!", "storage");
            }
        }
Esempio n. 2
0
 public virtual void SaveSecure(string tag, string data, string userId = null)
 {
     if (!string.IsNullOrEmpty(data))
     {
         bool flag = false;
         try
         {
             string fileName = GetFileName(tag, userId);
             SwrveLog.Log("Saving: " + fileName, "storage");
             CrossPlatformFile.SaveText(fileName, data);
             string path  = fileName + "_SGT";
             string data2 = SwrveHelper.CreateHMACMD5(data, uniqueKey);
             CrossPlatformFile.SaveText(path, data2);
             flag = true;
         }
         catch (Exception ex)
         {
             SwrveLog.LogError(ex.ToString(), "storage");
         }
         if (!flag)
         {
             SwrveLog.LogWarning(tag + " not saved!", "storage");
         }
     }
 }
Esempio n. 3
0
        public virtual string LoadSecure(string tag, string userId = null)
        {
            string text     = null;
            string fileName = GetFileName(tag, userId);

            try
            {
                string text2 = fileName + "_SGT";
                if (CrossPlatformFile.Exists(fileName))
                {
                    text = CrossPlatformFile.LoadText(fileName);
                    if (!string.IsNullOrEmpty(text))
                    {
                        string text3 = null;
                        if (CrossPlatformFile.Exists(text2))
                        {
                            text3 = CrossPlatformFile.LoadText(text2);
                        }
                        else
                        {
                            SwrveLog.LogError("Could not read signature file: " + text2);
                            text = null;
                        }
                        if (!string.IsNullOrEmpty(text3))
                        {
                            string value = SwrveHelper.CreateHMACMD5(text, uniqueKey);
                            if (string.IsNullOrEmpty(value))
                            {
                                SwrveLog.LogError("Could not compute signature for data in file " + fileName);
                                text = null;
                            }
                            else if (!text3.Equals(value))
                            {
                                if (callback != null)
                                {
                                    callback();
                                }
                                SwrveLog.LogError("Signature validation failed for " + fileName);
                                text = null;
                            }
                        }
                    }
                    else
                    {
                        SwrveLog.LogError("Could not read file " + fileName);
                    }
                }
            }
            catch (Exception ex)
            {
                SwrveLog.LogError(ex.ToString(), "storage");
            }
            return(text);
        }
Esempio n. 4
0
        public virtual string Load(string tag, string userId = null)
        {
            string result = null;

            try
            {
                string fileName = GetFileName(tag, userId);
                if (CrossPlatformFile.Exists(fileName))
                {
                    result = CrossPlatformFile.LoadText(fileName);
                }
            }
            catch (Exception ex)
            {
                SwrveLog.LogError(ex.ToString(), "storage");
            }
            return(result);
        }
        public virtual string Load(string tag, string userId = null)
        {
            string result = null;

            try {
                // Read from file
                string loadFileName = GetFileName(tag, userId);
                if (CrossPlatformFile.Exists(loadFileName))
                {
                    result = CrossPlatformFile.LoadText(loadFileName);
                }
                else
                {
                    // Skipping file load, doesn't exist
                }
            } catch (Exception e) {
                SwrveLog.LogError(e.ToString(), "storage");
            }

            return(result);
        }
Esempio n. 6
0
 public virtual void Remove(string tag, string userId = null)
 {
     try
     {
         string fileName = GetFileName(tag, userId);
         if (CrossPlatformFile.Exists(fileName))
         {
             SwrveLog.Log("Removing: " + fileName, "storage");
             CrossPlatformFile.Delete(fileName);
         }
         string path = fileName + "_SGT";
         if (CrossPlatformFile.Exists(path))
         {
             CrossPlatformFile.Delete(path);
         }
     }
     catch (Exception ex)
     {
         SwrveLog.LogError(ex.ToString(), "storage");
     }
 }
Esempio n. 7
0
 public virtual void Save(string tag, string data, string userId = null)
 {
     if (!string.IsNullOrEmpty(data))
     {
         bool flag = false;
         try
         {
             string fileName = GetFileName(tag, userId);
             SwrveLog.Log("Saving: " + fileName, "storage");
             CrossPlatformFile.SaveText(fileName, data);
             flag = true;
         }
         catch (Exception ex)
         {
             SwrveLog.LogError(ex.ToString(), "storage");
         }
         if (!flag)
         {
             SwrveLog.LogWarning(tag + " not saved!", "storage");
         }
     }
 }
        public virtual void Save(string tag, string data, string userId = null)
        {
            if (string.IsNullOrEmpty(data))
            {
                return;
            }

            bool saved = false;

            try {
                string saveFileName = GetFileName(tag, userId);
                SwrveLog.Log("Saving: " + saveFileName, "storage");
                CrossPlatformFile.SaveText(saveFileName, data);
                saved = true;
            } catch (Exception e) {
                SwrveLog.LogError(e.ToString(), "storage");
            }

            if (!saved)
            {
                SwrveLog.LogWarning(tag + " not saved!", "storage");
            }
        }
        public virtual void Remove(string tag, string userId = null)
        {
            try {
                // Read from file
                string deleteFilename = GetFileName(tag, userId);
                if (CrossPlatformFile.Exists(deleteFilename))
                {
                    SwrveLog.Log("Removing: " + deleteFilename, "storage");
                    CrossPlatformFile.Delete(deleteFilename);
                }
                else
                {
                    // Skipping file removal, doesn't exist
                }

                string signatureFileName = deleteFilename + SIGNATURE_SUFFIX;
                if (CrossPlatformFile.Exists(signatureFileName))
                {
                    CrossPlatformFile.Delete(signatureFileName);
                }
            } catch (Exception e) {
                SwrveLog.LogError(e.ToString(), "storage");
            }
        }
        public virtual string LoadSecure(string tag, string userId = null)
        {
            string result = null;

            // Read from file
            string loadFileName      = GetFileName(tag, userId);
            string signatureFileName = loadFileName + SIGNATURE_SUFFIX;

            if (CrossPlatformFile.Exists(loadFileName))
            {
                result = CrossPlatformFile.LoadText(loadFileName);

                if (!string.IsNullOrEmpty(result))
                {
                    string signature = null;
                    if (CrossPlatformFile.Exists(signatureFileName))
                    {
                        signature = CrossPlatformFile.LoadText(signatureFileName);
                    }
                    else
                    {
                        SwrveLog.LogError("Could not read signature file: " + signatureFileName);
                        result = null;
                    }

                    if (!string.IsNullOrEmpty(signature))
                    {
                        string computedSignature = SwrveHelper.CreateHMACMD5(result, uniqueKey);

                        if (string.IsNullOrEmpty(computedSignature))
                        {
                            SwrveLog.LogError("Could not compute signature for data in file " + loadFileName);
                            result = null;
                        }
                        else
                        {
                            if (!signature.Equals(computedSignature))
                            {
                                // Notify of invalid signature
                                if (callback != null)
                                {
                                    callback.Invoke();
                                }
                                SwrveLog.LogError("Signature validation failed for " + loadFileName);
                                result = null;
                            }
                        }
                    }
                }
                else
                {
                    SwrveLog.LogError("Could not read file " + loadFileName);
                }
            }
            else
            {
                // No cache available
            }

            return(result);
        }