Example #1
0
        public static void SaveDiffs()
        {
            if (Constants.isNoop)
            {
                return;
            }
            if (String.IsNullOrEmpty(LeanplumRequest.Token))
            {
                return;
            }

            string variablesCipher     = Json.Serialize(diffs);
            string fileAttributeCipher = Json.Serialize(fileAttributes);

            string messagesCipher = Json.Serialize(Messages);

            LeanplumNative.CompatibilityLayer.StoreSavedString(Constants.Defaults.MESSAGES_KEY,
                                                               AESCrypt.Encrypt(messagesCipher, LeanplumRequest.Token));

            LeanplumNative.CompatibilityLayer.StoreSavedString(Constants.Defaults.VARIABLES_KEY,
                                                               AESCrypt.Encrypt(variablesCipher, LeanplumRequest.Token));
            LeanplumNative.CompatibilityLayer.StoreSavedString(Constants.Defaults.FILE_ATTRIBUTES_KEY,
                                                               AESCrypt.Encrypt(fileAttributeCipher, LeanplumRequest.Token));
            if (!String.IsNullOrEmpty(LeanplumRequest.UserId))
            {
                LeanplumNative.CompatibilityLayer.StoreSavedString(Constants.Defaults.USERID_KEY,
                                                                   AESCrypt.Encrypt(LeanplumRequest.UserId, LeanplumRequest.Token));
            }
            LeanplumNative.CompatibilityLayer.StoreSavedString(Constants.Defaults.TOKEN_KEY, LeanplumRequest.Token);
            LeanplumNative.CompatibilityLayer.FlushSavedSettings();
        }
Example #2
0
        public static void LoadDiffs()
        {
            if (Constants.isNoop)
            {
                return;
            }
            string token = LeanplumNative.CompatibilityLayer.GetSavedString(Constants.Defaults.TOKEN_KEY);

            if (token == null)
            {
                return;
            }
            LeanplumRequest.Token = token;
            string variablesCipher      = LeanplumNative.CompatibilityLayer.GetSavedString(Constants.Defaults.VARIABLES_KEY, "{}");
            string fileAttributesCipher =
                LeanplumNative.CompatibilityLayer.GetSavedString(Constants.Defaults.FILE_ATTRIBUTES_KEY, "{}");

            string messagesCipher = LeanplumNative.CompatibilityLayer.GetSavedString(Constants.Defaults.MESSAGES_KEY, "{}");

            string userIdCipher = LeanplumNative.CompatibilityLayer.GetSavedString(Constants.Defaults.USERID_KEY);

            if (!String.IsNullOrEmpty(userIdCipher))
            {
                LeanplumRequest.UserId = AESCrypt.Decrypt(userIdCipher, LeanplumRequest.Token);
            }

            ApplyVariableDiffs(
                Json.Deserialize(variablesCipher == "{}" ? variablesCipher :
                                 AESCrypt.Decrypt(variablesCipher, LeanplumRequest.Token))
                as IDictionary <string, object>,
                Json.Deserialize(messagesCipher == "{}" ? messagesCipher : AESCrypt.Decrypt(messagesCipher, LeanplumRequest.Token)) as IDictionary <string, object>,
                Json.Deserialize(fileAttributesCipher == "{}" ? fileAttributesCipher :
                                 AESCrypt.Decrypt(fileAttributesCipher, LeanplumRequest.Token))
                as IDictionary <string, object>);
        }
Example #3
0
        public static void LoadDiffs()
        {
            if (Constants.isNoop)
            {
                return;
            }
            if (string.IsNullOrEmpty(Leanplum.ApiConfig.Token))
            {
                return;
            }

            string variablesCipher      = LeanplumNative.CompatibilityLayer.GetSavedString(Constants.Defaults.VARIABLES_KEY, "{}");
            string fileAttributesCipher =
                LeanplumNative.CompatibilityLayer.GetSavedString(Constants.Defaults.FILE_ATTRIBUTES_KEY, "{}");

            string messagesCipher = LeanplumNative.CompatibilityLayer.GetSavedString(Constants.Defaults.MESSAGES_KEY, "{}");

            string userIdCipher = LeanplumNative.CompatibilityLayer.GetSavedString(Constants.Defaults.USERID_KEY);

            if (!string.IsNullOrEmpty(userIdCipher))
            {
                Leanplum.ApiConfig.UserId = AESCrypt.Decrypt(userIdCipher, Leanplum.ApiConfig.Token);
            }

            string varsJsonCipher      = LeanplumNative.CompatibilityLayer.GetSavedString(Constants.Defaults.VARIABLES_JSON_KEY, null);
            string varsSignatureCipher = LeanplumNative.CompatibilityLayer.GetSavedString(Constants.Defaults.VARIABLES_SIGN_KEY, null);
            string varsJson            = varsJsonCipher != null?AESCrypt.Decrypt(varsJsonCipher, Leanplum.ApiConfig.Token) : null;

            string varsSignature = varsSignatureCipher != null?AESCrypt.Decrypt(varsSignatureCipher, Leanplum.ApiConfig.Token) : null;

            ApplyVariableDiffs(
                DeserializeEncryptedData(variablesCipher),
                DeserializeEncryptedData(messagesCipher),
                DeserializeEncryptedData(fileAttributesCipher),
                null,
                varsJson,
                varsSignature);
        }
Example #4
0
        private static void StoreEncrypted(string key, string serializedData)
        {
            string encrypted = AESCrypt.Encrypt(serializedData, Leanplum.ApiConfig.Token);

            LeanplumNative.CompatibilityLayer.StoreSavedString(key, encrypted);
        }
Example #5
0
 private static IDictionary <string, object> DeserializeEncryptedData(string dataCipher)
 {
     return(Json.Deserialize(dataCipher == "{}" ? dataCipher :
                             AESCrypt.Decrypt(dataCipher, Leanplum.ApiConfig.Token))
            as IDictionary <string, object>);
 }