public virtual async Task <string> DecryptSecretAsync(string id) { var secret = await _secretStore.GetAsync(id); if (secret == null) { _decryptFailedEventArgs.FailureReason = "Invalid secret ID"; _context.OnDecryptionFailed?.Invoke(this, _decryptFailedEventArgs); return(null); } Secret = secret; var result = ValidateSecret(ValidationStage.BeforeDecrypt); if (result.IsValid) { try { var decrypted = DecryptSecret(); await _secretStore.DeleteAsync(Secret.Id); _logger.LogDebug("Secret decrypted and deleted"); _context.OnSecretDecrypted?.Invoke(this, _decryptEventArgs); return(decrypted); } catch (Exception e) { _logger.LogDebug("Decryption failed"); await IncrementFailedDecryptions(); _decryptFailedEventArgs.FailureReason = e.Message; _decryptFailedEventArgs.Exception = e; _decryptFailedEventArgs.ValidationResult = new ValidationResult(false) { ValidationPointOfFailure = "Decryption", Error = "Decryption failed" }; _context.OnDecryptionFailed?.Invoke(this, _decryptFailedEventArgs); return(null); } } else { _logger.LogDebug("Decryption invalid"); await IncrementFailedDecryptions(); _decryptFailedEventArgs.ValidationResult = result; _decryptFailedEventArgs.FailureReason = "Validation failed"; _context.OnDecryptionFailed?.Invoke(this, _decryptFailedEventArgs); return(null); } }
public async Task <IActionResult> Delete(string k) { var email = User.FindFirstValue(ClaimTypes.Email); var secret = await _secretStore.GetAsync(k); if (!string.IsNullOrEmpty(email) && secret?.CreatedBy == email) { await _secretStore.DeleteAsync(k); } return(RedirectToAction("Index", new{ deleted = k })); }
public async Task DeleteAsync(string key) { await _secretStore.DeleteAsync(key).ConfigureAwait(false); }