Example #1
0
        static Task PlatformSetAsync(string key, string data)
        {
            var context = Platform.AppContext;

            var ks            = new AndroidKeyStore(context, Alias, AlwaysUseAsymmetricKeyStorage);
            var encryptedData = ks.Encrypt(data);

            var encStr = Convert.ToBase64String(encryptedData);

            Preferences.Set(Utils.Md5Hash(key), encStr, Alias);

            return(Task.CompletedTask);
        }
        static Task PlatformSetAsync(string key, string data)
        {
            var context = Platform.AppContext;

            var ks            = new AndroidKeyStore(context, Alias, AlwaysUseAsymmetricKeyStorage);
            var encryptedData = ks.Encrypt(data);

            using (var prefs = context.GetSharedPreferences(Alias, FileCreationMode.Private))
                using (var prefsEditor = prefs.Edit())
                {
                    var encStr = Convert.ToBase64String(encryptedData);
                    prefsEditor.PutString(Utils.Md5Hash(key), encStr);
                    prefsEditor.Commit();
                }

            return(Task.CompletedTask);
        }
        static Task PlatformSetAsync(string key, string data)
        {
            var context = Platform.AppContext;

            byte[] encryptedData = null;
            lock (locker)
            {
                var ks = new AndroidKeyStore(context, Alias, AlwaysUseAsymmetricKeyStorage);
                encryptedData = ks.Encrypt(data);
            }

            var encStr = Convert.ToBase64String(encryptedData);

            Preferences.Set(key, encStr, Alias);

            CheckForAndRemoveLegacyKey(key);

            return(Task.CompletedTask);
        }