Reputation: 1049
As you know akavache has issues with its secure storage on iOS and Android. I am trying to override the secure storage used by Akavache.
I've been following the example given by Kent to solve this problem: http://kent-boogaart.com/blog/password-protected-encryption-provider-for-akavache
Note: I cannot use System.Security.Cryptography
in my code, because we are using PCL's. Therefore I am using PCLCrypto
.
I use a setup class to initialize DI:
IPasswordProtectedEncryptionProvider providerInstance = new PasswordProtectedEncryptionProvider();
providerInstance.SetPassword("test");
Splat.Locator.CurrentMutable.Register(() => providerInstance, typeof(Akavache.IEncryptionProvider));
Container.RegisterSingleton<ICache>(new CacheManager());
I use PasswordProtectedEncryptionProvider
as my custom override of IEncryptionProvider
. However the methods overridden in the class, DecryptBlock
EncryptBlock
, do not get called!
Don't understand why its not being called.
Doesn't () => providerInstance
override it?
Upvotes: 1
Views: 154
Reputation: 895
Depending on the timing of your registration, and the way you get your secure cache, it may be getting LIFO'd by Akavache's default registrations.
To avoid the ambiguity (and for cleaner DI), I typically set up my encrypted caches as below:
var fsprovider = Locator.Current.GetService<IFilesystemProvider>();
var root = fsprovider.GetDefaultSecretCacheDirectory();
var dbName = "mysecrets.db";
var path = Path.Combine(root, dbName);
var encryptionProvider = /* create + init or resolve your enc provider here */
var encryptedCache = new SQLiteEncryptedBlobCache(path, encryptionProvider);
To solve your specific issue, initialize the cache manager ahead of the DI:
CacheManager _cache = new CacheManager();
IPasswordProtectedEncryptionProvider providerInstance = new PasswordProtectedEncryptionProvider();
providerInstance.SetPassword("test");
Splat.Locator.CurrentMutable.Register(() => providerInstance, typeof(Akavache.IEncryptionProvider));
Container.RegisterSingleton<ICache>(_cache);
Upvotes: 2