public IActionResult Decrypt([FromBody] DecryptionRequest request)
 {
     try
     {
         var decrypted = SecretService.Decrypt(request.Payload, request.Key);
         return(Ok(decrypted));
     }
     catch (Exception)
     {
         return(BadRequest(request.Key));
     }
 }
Пример #2
0
        public void Decrypt(DecryptionRequest req)
        {
            string cmdArgs;

            try
            {
                cmdArgs = req.Execute();
                using (System.IO.FileStream fsDecryptFile = new System.IO.FileStream(this.fullPathToPgpRoot + "\\" + req.File.Name, System.IO.FileMode.Create))
                    using (System.IO.FileStream fsPrivateKeyFile = new System.IO.FileStream(this.fullPathToPgpRoot + "\\" + req.CryptionArgs.PrivateKey.Name, System.IO.FileMode.Create))
                        using (System.IO.FileStream fsPassphraseFile = new System.IO.FileStream(this.fullPathToPgpRoot + "\\" + req.CryptionArgs.PassPhrase.Name, System.IO.FileMode.Create))
                        {
                            fsDecryptFile.Write(req.File.Content, 0, req.File.Content.Length);
                            fsPrivateKeyFile.Write(req.CryptionArgs.PrivateKey.Content, 0, req.File.Content.Length);
                            fsPassphraseFile.Write(req.CryptionArgs.PassPhrase.Content, 0, req.File.Content.Length);
                        }
            }
            catch (Exception)
            {
                throw;
            }

            if (this.ExecuteGnuGpg(cmdArgs))
            {
                System.IO.FileInfo decryptedFile = new System.IO.FileInfo(String.Format("{0}\\{1}", this.workingDir, req.File.Name.Replace(".gpg", "")));
                if (decryptedFile.Exists)
                {
                    var callback = this.clientCallback;
                    if (callback != null)
                    {
                        byte[] fileContent = System.IO.File.ReadAllBytes(decryptedFile.FullName);
                        callback.OnFileDecrypted(new FileCryptionEvent {
                            File = new File(decryptedFile.Name, fileContent), ExecutedCommand = cmdArgs
                        });
                    }
                }
            }
        }