/// <summary>
 /// 通过密钥对文本进行加密
 /// </summary>
 /// <param name="str"></param>
 /// <param name="SecretKey">密钥</param>
 /// <param name="SingleLine">True:单行;False:所有</param>
 /// <param name="Standard">是否使用标准方式</param>
 /// <returns>加密后的文本</returns>
 public static string Encrypt(this string str, string SecretKey, bool SingleLine = true, bool Standard = false)
 {
     DESCryptoServiceProvider des = new DESCryptoServiceProvider();
     if (Standard)
     {
         des.Mode = CipherMode.ECB;
         des.Padding = PaddingMode.Zeros;
     }
     des.Key = SecretKey.ToMD5().Substring(0, 0x08).ToBytes();
     des.IV = SecretKey.ToMD5().Substring(0, 0x08).ToBytes();
     global::System.IO.MemoryStream ms = new global::System.IO.MemoryStream();
     CryptoStream encStream = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
     global::System.IO.StreamWriter sw = new global::System.IO.StreamWriter(encStream);
     if (SingleLine)
         sw.WriteLine(str);
     else
         sw.Write(str);
     sw.Close();
     encStream.Close();
     byte[] buffer = ms.ToArray();
     ms.Close();
     StringBuilder hash = new StringBuilder();
     foreach (byte b in buffer.ToArray())
     {
         hash.AppendFormat("{0:X2}", b);
     }
     return hash.ToString();
 }
Exemple #2
0
        public bool Replace(string line, string to)
        {
            if (tw == null)
            {
                return(false);
            }

            try
            {
                FileInfo fi = new FileInfo(_path);
                fi.CopyTo(_path + ".tmp");

                tw.Close();
                tw = new StreamWriter(_path, false);

                StreamReader sr = new StreamReader(_path + ".tmp");
                string       l, id = "";
                while ((l = sr.ReadLine()) != null)
                {
                    int pos = l.IndexOf(":");
                    if (pos != -1)
                    {
                        id = l.Substring(0, pos);
                        l  = l.Substring(pos + 1, l.Length - pos - 1);
                    }
                    if (l == line)
                    {
                        tw.WriteLine(id + ":" + to);
                    }
                    else
                    {
                        tw.WriteLine(id + ":" + l);
                    }
                }
                sr.Close();
                tw.Close();
                fi = new FileInfo(_path + ".tmp");
                fi.Delete();

                tw = new StreamWriter(_path, true);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemple #3
0
        public bool ReplaceHoleLine(string line, string to)
        {
            if (tw == null)
            {
                return(false);
            }

            try
            {
                bool     ret = false;
                FileInfo fi  = new FileInfo(_path);
                fi.CopyTo(_path + ".tmp");

                tw.Close();
                tw = new StreamWriter(_path, false);

                StreamReader sr = new StreamReader(_path + ".tmp");
                string       l;
                while ((l = sr.ReadLine()) != null)
                {
                    if (l == line)
                    {
                        tw.WriteLine(to);
                        ret = true;
                    }
                    else
                    {
                        tw.WriteLine(l);
                    }
                }
                sr.Close();
                tw.Close();
                fi = new FileInfo(_path + ".tmp");
                fi.Delete();

                tw = new StreamWriter(_path, true);
                return(ret);
            }
            catch
            {
                return(false);
            }
        }
Exemple #4
0
 // Token: 0x06000488 RID: 1160 RVA: 0x00017428 File Offset: 0x00015628
 public void SaveDictionary(string path)
 {
     this.EnsurePath(path);
     using (global::System.IO.StreamWriter streamWriter = new global::System.IO.StreamWriter(global::System.IO.File.Open(path, 4), global::System.Text.Encoding.UTF8))
     {
         streamWriter.BaseStream.SetLength(0L);
         foreach (global::System.Reflection.FieldInfo fieldInfo in global::VRGIN.Controls.Speech.DictionaryReader.ExtractCommands(this.BaseType))
         {
             streamWriter.WriteLine("[{0}]", fieldInfo.Name);
             global::VRGIN.Controls.Speech.VoiceCommand voiceCommand = fieldInfo.GetValue(null) as global::VRGIN.Controls.Speech.VoiceCommand;
             bool flag = voiceCommand != null;
             if (flag)
             {
                 foreach (string text in voiceCommand.Texts)
                 {
                     streamWriter.WriteLine(text);
                 }
             }
             streamWriter.WriteLine();
         }
     }
 }
Exemple #5
0
        public bool Write(string line, ref string id)
        {
            id = id.Replace(":", _dp);

            if (tw == null)
            {
                return(false);
            }

            id = ModifyID(id);
            tw.WriteLine(id + ":" + line);
            return(true);
        }
Exemple #6
0
        private static void menuCommonLVExportToTextFile_Click(
            object sender,
            EventArgs e)
        {
            var lvCtx = GetCommonLVContext(sender);
            if (lvCtx == null)
                return;

            var lv = lvCtx.lv;

            string fn = Dialogs.FileSysDialogs.BrowseFile(
                lvCtx.options.ExportDefaultDirectory?? Path.GetDirectoryName((new FileInfo(global::System.Reflection.Assembly.GetExecutingAssembly().Location)).FullName),
                "",
                lvCtx.options.ExportDefaultExtensions,
                lvCtx.options.ExportDefaultFilter,
                true);
            if (string.IsNullOrEmpty(fn))
                return;

            using (TextWriter Out = new global::System.IO.StreamWriter(fn, false))
            {
                // Write column header
                foreach (MSWinForms.ColumnHeader Cur in lv.Columns)
                {
                    Out.Write("\"" + Cur.Text + "\"");
                    Out.Write(lvCtx.options.CopyItemsSeparator);
                }
                Out.WriteLine();

                foreach (MSWinForms.ListViewItem Item in lv.Items)
                    Out.WriteLine(Item.GetItemsString());

                Out.Close();
            }
        }