Ejemplo n.º 1
0
 private static void RetrieveArgon2Parameters(string filePath, ref string memorySize, ref string iterations)
 {
     try
     {
         // Read the first line of the file
         using (var streamReader = new StreamReader(filePath, true))
         {
             string firstLine       = streamReader.ReadLine();
             int    memorySizeIndex = firstLine.IndexOf(Constants.MemorySizeFlag, StringComparison.Ordinal);
             if (memorySizeIndex != -1)
             {
                 int iterationsIndex = firstLine.IndexOf(Constants.IterationsFlag, StringComparison.Ordinal);
                 int endIndex        = firstLine.IndexOf(Constants.EndFlag, StringComparison.Ordinal);
                 // If the strings are found on the line
                 if (memorySizeIndex != -1 && iterationsIndex != -1 && endIndex != -1)
                 {
                     memorySize = firstLine.Substring(memorySizeIndex, iterationsIndex - memorySizeIndex);
                     iterations = firstLine.Substring(iterationsIndex, endIndex - iterationsIndex);
                 }
             }
         }
     }
     catch (Exception ex) when(ExceptionFilters.FileAccessExceptions(ex) || ExceptionFilters.CharacterEncodingExceptions(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.High);
         DisplayMessage.ErrorResultsText(filePath, ex.GetType().Name, "Unable to read Argon2 parameters from the file.");
     }
 }
Ejemplo n.º 2
0
 private static int GetFileNameLength(string filePath, string originalFileName)
 {
     try
     {
         EncodeFileName(filePath, originalFileName, out byte[] newLineBytes, out byte[] fileNameBytes);
         return(newLineBytes.Length + fileNameBytes.Length);
     }
     catch (Exception ex) when(ExceptionFilters.CharacterEncodingExceptions(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.High);
         DisplayMessage.ErrorResultsText(filePath, ex.GetType().Name, "Unable to remove the original file name stored in the file. The length of the stored file name could not be calculated.");
         return(0);
     }
 }
Ejemplo n.º 3
0
 public static (byte[], byte[], byte[]) GetParametersBytes(string memorySize, string iterations)
 {
     try
     {
         Encoding encoding        = Encoding.UTF8;
         byte[]   memorySizeBytes = encoding.GetBytes(memorySize);
         byte[]   iterationsBytes = encoding.GetBytes(iterations);
         byte[]   endFlagBytes    = encoding.GetBytes(Constants.EndFlag);
         return(memorySizeBytes, iterationsBytes, endFlagBytes);
     }
     catch (Exception ex) when(ExceptionFilters.CharacterEncodingExceptions(ex))
     {
         Logging.LogException(ex.ToString(), Logging.Severity.High);
         DisplayMessage.ErrorResultsText(string.Empty, ex.GetType().Name, "Unable to convert Argon2 parameters to bytes.");
         return(null, null, null);
     }
 }