public ShellForm(List <string> fileNames, HashHelper.HashType type) : this() { this.hashType = type; this.fileNames = fileNames; KeyValuePair <HashHelper.HashType, List <string> > pair = new KeyValuePair <HashHelper.HashType, List <string> >(type, fileNames); bgWorker.RunWorkerAsync(pair); }
public ShellForm(List<string> fileNames, HashHelper.HashType type) : this() { this.hashType = type; this.fileNames = fileNames; KeyValuePair<HashHelper.HashType, List<string>> pair = new KeyValuePair<HashHelper.HashType, List<string>>(type, fileNames); bgWorker.RunWorkerAsync(pair); }
/// <summary> /// Creates the digest portion of the ticket from the provided data. /// </summary> /// <param name="ticketData">Data used to create the digest</param> /// <param name="secret">Secret key used to create the digest</param> /// <returns>Digest string</returns> /// <remarks> /// The algorithm for the digest is as follows: /// digest = MD5(digest0 + key) /// where /// Version 1.3: digest0 = MD5(iptstamp + key + user_id + user_data) /// Version 2.0: digest0 = MD5(iptstamp + key + user_id + '\0' + token_list + '\0' + user_data) /// </remarks> private static string CreateDigest(AuthenticationTicketData ticketData, string secret) { if (ticketData == null) { return(null); } if (string.IsNullOrWhiteSpace(secret)) { secret = DefaultSecret; } string iptStamp = CreateIPTimeStamp(ticketData.IPAddressAsInt, ticketData.UnixTimeStamp); string digest; const HashHelper.HashType hashType = HashHelper.HashType.MD5; switch (ticketData.Version) { case "1.3": digest = HashHelper.Hash(iptStamp + secret + ticketData.UserId + ticketData.UserData, hashType); digest = HashHelper.Hash(digest + secret, hashType); break; case "2.0": digest = HashHelper.Hash( iptStamp + secret + ticketData.UserId + '\0' + ticketData.TokensAsString + '\0' + ticketData.UserData, hashType); digest = HashHelper.Hash(digest + secret, hashType); break; default: throw new NotSupportedException(string.Format("Version {0} of the mod_auth_tkt algorithm is not supported", ticketData.Version)); } return(digest); }
private void bgWorker_DoWork(object sender, DoWorkEventArgs e) { BindingList <FileInformation> data = new BindingList <FileInformation>(); if (e.Argument is KeyValuePair <HashHelper.HashType, List <string> > ) { List <string> files = ((KeyValuePair <HashHelper.HashType, List <string> >)e.Argument).Value; HashHelper.HashType type = ((KeyValuePair <HashHelper.HashType, List <string> >)e.Argument).Key; foreach (string file in files) { FileInfo fileInf = new FileInfo(file); FileInformation inf = new FileInformation(); inf.Name = fileInf.Name; bgWorker.ReportProgress(0, fileInf.Name); inf.Path = fileInf.FullName; inf.Hash = HashHelper.GetFileHash(file, type); inf.FileDate = fileInf.LastWriteTime; inf.FileSize = (Int64)fileInf.Length / 1000; data.Add(inf); } } e.Result = data; }
public static List <LogInfo> Hash(EngineState s, CodeCommand cmd) { List <LogInfo> logs = new List <LogInfo>(); CodeInfo_Hash info = cmd.Info.Cast <CodeInfo_Hash>(); string hashTypeStr = StringEscaper.Preprocess(s, info.HashType); string filePath = StringEscaper.Preprocess(s, info.FilePath); Debug.Assert(hashTypeStr != null, $"{nameof(hashTypeStr)} != null"); Debug.Assert(filePath != null, $"{nameof(filePath)} != null"); if (!File.Exists(filePath)) { return(LogInfo.LogErrorMessage(logs, $"File [{filePath}] does not exist")); } long reportInterval = 0; FileInfo fi = new FileInfo(filePath); long fileSize = fi.Length; // If file size is larger than 32MB, turn on progress report if (ReportThreshold <= fileSize) { // reportInterval should be times of 1MB reportInterval = NumberHelper.Round(fileSize / 32, ReportRound); // If reportInterval is larger than 128MB, limit to 128MB if (ReportIntervalMax < reportInterval) { reportInterval = ReportIntervalMax; } } string digest; HashHelper.HashType hashType = HashHelper.ParseHashType(hashTypeStr); if (0 < reportInterval) { s.MainViewModel.SetBuildCommandProgress("Hash Progress"); } try { IProgress <long> progress = new Progress <long>(pos => { double percent = (double)pos / fileSize * 100; s.MainViewModel.BuildCommandProgressValue = percent; s.MainViewModel.BuildCommandProgressText = $"Hashing {hashType}... ({percent:0.0}%)"; }); byte[] rawDigest; using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { if (0 < reportInterval) { rawDigest = HashHelper.GetHash(hashType, fs, reportInterval, progress); } else { rawDigest = HashHelper.GetHash(hashType, fs); } } digest = StringHelper.ToHexStr(rawDigest); } finally { if (0 < reportInterval) { s.MainViewModel.ResetBuildCommandProgress(); } } logs.Add(new LogInfo(LogState.Success, $"Hash [{hashType}] digest of [{filePath}] is [{digest}]")); List <LogInfo> varLogs = Variables.SetVariable(s, info.DestVar, digest); logs.AddRange(varLogs); return(logs); }
public void OpenShellForm(HashHelper.HashType hashType) { var frm = new ShellForm(SelectedItemPaths.ToList(), hashType); frm.Show(); }