SecureStorage Class

Definition

Provides simple secure storage for key/value pairs.

public static class SecureStorage
Inheritance
SecureStorage

Remarks

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.

Properties

DefaultAccessible

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

LegacyKeyHashFallback

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.

Methods

GetAsync(String)

Gets the decrypted value for a given Key.

Remove(String)

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

RemoveAll()

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