/// <inheritdoc /> public async Task InitializeFirstTimeAndGenerate(string password, string protectedStoreFileName = "Excalibur.Store") { // Store the password _password = password; try { _protectedStore.Initialize(DeviceKey(), protectedStoreFileName); } catch (ProtectedStoreException) { _protectedStore.Remove(); _protectedStore.Terminate(); _protectedStore.Initialize(DeviceKey(), protectedStoreFileName); } // We generate an encryption key for the protected store key var keySalt = _crypto.GenerateRandom(32); var key = _crypto.CreateDerivedKey(_password, keySalt); // Generate some salt we use for encrypting / decrypting just the combinationKey var combinationKeySalt = _crypto.GenerateRandom(32); await _protectedStore.Save(ProtectedStoreDeviceSaltIdentifier, Convert.ToBase64String(combinationKeySalt)).ConfigureAwait(false); // We encrypt the key with the above information and store it for later use var keyEncrypted = _crypto.EncryptFromBytes(key, DeviceKey(), combinationKeySalt); await _protectedStore.Save(ProtectedStoreKeyIdentifier, Convert.ToBase64String(keyEncrypted)).ConfigureAwait(false); // We need some salt for storage encryption var storeSalt = _crypto.GenerateRandom(32); await _protectedStore.Save(ProtectedStoreSaltIdentifier, Convert.ToBase64String(storeSalt)).ConfigureAwait(false); await EncryptAndStoreTest().ConfigureAwait(false); HasBeenInitialized = true; }
/// <inheritdoc /> public void Clear() { _password = null; _protectedStore.Terminate(); HasBeenInitialized = false; }