Esempio n. 1
0
        public async Task <IActionResult> DecryptSecret(SecretRetrieveModel model)
        {
            using (var decryptContext = _secretContextService.CreateDecryptionContext(User))
            {
                decryptContext.InputData.Add(UserInputConstants.Passphrase, model.Passphrase);
                decryptContext.InputData.Add(UserInputConstants.IpAddress, Request.GetIpAddress());

                var result = await decryptContext.PreProcessAsync(model.Id);

                if (result.IsValid)
                {
                    var decrypted = await decryptContext.DecryptSecretAsync(model.Id);

                    if (decrypted == null)
                    {
                        return(new BadRequestResult());
                    }
                    return(Json(decrypted));
                }
                else
                {
                    return(new BadRequestResult());
                }
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> Secret(string k)
        {
            using (var decryptContext = _secretContextService.CreateDecryptionContext(User))
            {
                try
                {
                    var result = await decryptContext.PreProcessAsync(k);

                    if (result.IsValid)
                    {
                        var model = new SecretRetrieveModel()
                        {
                            Id = k
                        };
                        return(View(model));
                    }
                    else
                    {
                        return(View("NoSecret"));
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError(e, e.Message);
                    return(View("NoSecret"));
                }
            }
        }