SecureStorage Class


Provides simple secure storage for key/value pairs.

public static class SecureStorage


Each platform uses the platform provided native API's for storing data securely:

  • iOS: Data is stored in KeyChain. Additional information on SecAccessible at: SecAccessible
  • Android: Encryption keys are stored in KeyStore and encrypted data is stored in a named shared preference container (PackageId.Xamarin.Essentials).
  • UWP: Data is encrypted with DataProtectionProvider and stored in a named ApplicationDataContainer (with a container name of ApplicationId.Xamarin.Essentials).

NOTE: On Android devices running below API 23 (6.0 Marshmallow) there is no AES available in KeyStore. As a best practice this API will generate an RSA/ECB/PKCS7Padding key pair stored in KeyStore (the only type supported in KeyStore by these lower API levels), which is used to wrap an AES key generated at runtime. This wrapped key is stored in Preferences.



iOS: Default SecAccessible to use for all Get/Set calls to KeyChain. Default value is AfterFirstUnlock.


When set to true if the key/value pair is not found, the MD5 key hash is also used to attempt to locate a value.



Gets the decrypted value for a given Key.


Removes the encrypted key/value pair for the given key.


Removes all of the stored encrypted key/value pairs.

SetAsync(String, String)

Stores the value which is encrypted, for a given Key.

SetAsync(String, String, SecAccessible)

Stores the value which is encrypted, for a given Key. iOS override to specify SecAccessible for the KeyChain.

Applies to