Exemple #1
0
        static Task <string> PlatformGetAsync(string key)
        {
            var context = Platform.CurrentContext;

            string encStr;

            using (var prefs = context.GetSharedPreferences(Alias, FileCreationMode.Private))
                encStr = prefs.GetString(Utils.Md5Hash(key), null);

            var encData = Convert.FromBase64String(encStr);

            var ks            = new AndroidKeyStore(context, Alias, AlwaysUseAsymmetricKeyStorage);
            var decryptedData = ks.Decrypt(encData);

            return(Task.FromResult(decryptedData));
        }
Exemple #2
0
        static Task PlatformSetAsync(string key, string data)
        {
            var context = Platform.CurrentContext;

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