コード例 #1
0
        private static void SavePasswordToFile(string password, string fileName)
        {
            string value = DESManager.Encrypt(password);

            value = DESManager.Encrypt(value);
            value = DESManager.Encrypt(value);
            value = string.Join(" ", System.Text.RegularExpressions.Regex.Matches(value, @"..").Cast <System.Text.RegularExpressions.Match>().ToList());
            List <string> valueList = new List <string>();
            int           i         = 0;
            int           count     = value.Length / 36;

            for (i = 0; i < count; i++)
            {
                valueList.Add(value.Substring(i * 36, 36));
            }
            valueList.Add(value.Substring(i * 36));
            value = string.Join(Environment.NewLine, valueList);
            byte[] buff = Encoding.UTF8.GetBytes(value);
            System.IO.FileStream   stream = stream = new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite);
            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
            writer.Write(buff);
            writer.Close();
            writer.Dispose();
            stream.Close();
            stream.Dispose();
        }
コード例 #2
0
        private static string LoadPasswordFromFile(string fileName)
        {
            string      value    = "";
            List <byte> byteList = new List <byte>();

            System.IO.FileStream   stream = new System.IO.FileStream(FileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);
            while (reader.PeekChar() != -1)
            {
                byteList.Add(reader.ReadByte());
            }
            reader.Close();
            reader.Dispose();
            stream.Close();
            stream.Dispose();
            value = Encoding.UTF8.GetString(byteList.ToArray());
            value = value.Replace(Environment.NewLine, "");
            value = value.Replace(" ", "");
            value = DESManager.Decrypt(value);
            value = DESManager.Decrypt(value);
            value = DESManager.Decrypt(value);
            return(value);
        }