// reads the contents of the file and appends an MD5 private void SignRunLogFile() { var readConfigStream = new FileStream(_outputRunLogFileName, FileMode.Open, FileAccess.Read); string hashThis = ""; using (StreamReader streamConfigReader = new StreamReader(readConfigStream)) { hashThis = streamConfigReader.ReadToEnd(); } var writeConfigStream = new FileStream(_outputRunLogFileName, FileMode.Append, FileAccess.Write); using (StreamWriter streamConfigWriter = new StreamWriter(writeConfigStream)) { streamConfigWriter.WriteLine("----------------------------------------------------------"); streamConfigWriter.WriteLine("OpenPseudonymiser Config Security: " + CryptHelper.md5encrypt(hashThis + "seal")); } }
/// <summary> /// Takes a name value pair collection and produces the digest /// An exception is throw if GetDigest() is called without first setting the salt, or setting the salt to a blank string. /// Note all whitespace is stripped from the data in any field used here. /// </summary> /// <param name="nameValuePairs">One or more pairs of key/data to be used when creating the digest.</param> /// <returns>The Digest</returns> public string GetDigest(SortedList <string, string> nameValuePairs) { if (_salt == null || _salt == "") { throw new ApplicationException("Salt must be set before calling this method. Salt cannot be a blank string."); } // the fields get appended in alphabetical order, with the salt on the end string hashThis = ""; // Get the columns for the digest, this is a sorted list we always get aphabetically ordered keys foreach (string key in nameValuePairs.Keys) { hashThis += nameValuePairs[key]; } hashThis = RemoveBlanks(hashThis); hashThis += _salt; return(CryptHelper.sha256encrypt(hashThis)); }