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"); } }
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"); } } }
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); }
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); }