1
0
mirror of https://git.teknik.io/Teknikode/Teknik.git synced 2023-08-02 14:16:22 +02:00

Added checks to see if paste file exists.

This commit is contained in:
Uncled1023 2019-01-23 22:46:04 -08:00
parent 883318f871
commit 063854f776
2 changed files with 8 additions and 0 deletions

View File

@ -106,6 +106,11 @@ namespace Teknik.Areas.Paste.Controllers
// Read in the file
string subDir = paste.FileName[0].ToString();
string filePath = Path.Combine(_config.PasteConfig.PasteDirectory, subDir, paste.FileName);
if (!System.IO.File.Exists(filePath))
{
return new StatusCodeResult(StatusCodes.Status404NotFound);
}
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
using (AesCounterStream cs = new AesCounterStream(fs, false, keyBytes, ivBytes))
using (StreamReader sr = new StreamReader(cs, Encoding.Unicode))

View File

@ -110,6 +110,9 @@ namespace Teknik.Areas.Vault.Controllers
// Read in the file
string subDir = paste.Paste.FileName[0].ToString();
string filePath = Path.Combine(_config.PasteConfig.PasteDirectory, subDir, paste.Paste.FileName);
if (!System.IO.File.Exists(filePath))
continue;
byte[] ivBytes = Encoding.Unicode.GetBytes(paste.Paste.IV);
byte[] keyBytes = AesCounterManaged.CreateKey(paste.Paste.Key, ivBytes, paste.Paste.KeySize);
using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))