BudgetAnalyser.Engine.Services.ApplicationDatabaseService.DecryptFilesAsync C# (CSharp) Method

DecryptFilesAsync() public method

public DecryptFilesAsync ( object confirmCredentialsClaim ) : System.Threading.Tasks.Task
confirmCredentialsClaim object
return System.Threading.Tasks.Task
        public async Task DecryptFilesAsync(object confirmCredentialsClaim)
        {
            if (this.credentialStore.RetrievePasskey() == null)
            {
                throw new EncryptionKeyNotProvidedException("Attempt to use encryption but no password is set.");
            }

            if (!this.credentialStore.AreEqual(confirmCredentialsClaim))
            {
                throw new EncryptionKeyIncorrectException("The provided credential does not match the existing credential used to load the encrypted files.");
            }

            await CreateBackup(); // Ensure data is not corrupted and lost when encrypting files

            SetAllDirtyFlags(); // Ensure all files are marked as requiring a save.
            this.budgetAnalyserDatabase.IsEncrypted = false;

            await SaveAsync();

            // If the files are now unprotected (unencrypted) then ensure the password is no longer stored in memory.
            SetCredential(null);
        }