public static void WriteAllLines(string path, string[] lines) { FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write); if (Config.I.EncryptFiles) { stream.WriteByte(0); RC4Encryption enc = new RC4Encryption(Config.I.FilePassword); foreach (string line in lines) { for (int x = 0; x < line.Length; x++) { stream.WriteByte((byte)(line[x] ^ enc.NextByte())); } stream.WriteByte((byte)("\n".ToCharArray()[0] ^ enc.NextByte())); } } else { foreach (string line in lines) { for (int x = 0; x < line.Length; x++) { stream.WriteByte((byte)(line[x])); } stream.WriteByte((byte)("\n".ToCharArray()[0])); } } stream.Close(); }
public static void AppendText(string path, string text) { FileStream stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite); if (stream.ReadByte() == 0) { RC4Encryption enc = new RC4Encryption(Config.I.FilePassword); for (int x = 0; x < stream.Length; x++) { enc.NextByte(); } stream.Seek(0, SeekOrigin.End); for (int x = 0; x < text.Length; x++) { stream.WriteByte((byte)(text[x] ^ enc.NextByte())); } } else { stream.Seek(0, SeekOrigin.End); for (int x = 0; x < text.Length; x++) { stream.WriteByte((byte)(text[x])); } } stream.Close(); }
public static string ReadAllText(string path) { string plain = ""; FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); stream.Seek(0, SeekOrigin.Begin); if (stream.ReadByte() == 0) { //Encrypted RC4Encryption enc = new RC4Encryption(Config.I.FilePassword); int read = 0; while (read != -1 && stream.Position < stream.Length) { read = stream.ReadByte(); plain += (char)(read ^ enc.NextByte()); } } else { //Plain int read = 0; stream.Seek(0, SeekOrigin.Begin); while (read != -1 && stream.Position < stream.Length) { read = stream.ReadByte(); plain += (char)read; } } stream.Close(); return(plain); }
public static void EncryptFile(string path) { FileStream stream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite); RC4Encryption enc = new RC4Encryption(Config.I.FilePassword); while (stream.Position < stream.Length) { byte output = (byte)stream.ReadByte(); stream.Position--; stream.WriteByte((byte)(output ^ enc.NextByte())); } stream.Close(); }
public static string[] ReadAllLines(string path) { List<string> plain = new List<string>(); string plainBuf = ""; FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); if (stream.ReadByte() == 0) { //Encrypted RC4Encryption enc = new RC4Encryption(Config.I.FilePassword); int read = 0; while (read != -1 && stream.Position < stream.Length) { read = stream.ReadByte(); char p = (char)(read ^ enc.NextByte()); if (p == "\n".ToCharArray()[0]) { if (plainBuf.EndsWith("\r")) plainBuf.Remove(plainBuf.LastIndexOf("\r")); if (!string.IsNullOrEmpty(plainBuf)) plain.Add(plainBuf); plainBuf = ""; } else plainBuf += p; } } else { //Plain stream.Seek(0, SeekOrigin.Begin); int read = 0; while (read != -1 && stream.Position < stream.Length) { read = stream.ReadByte(); char p = (char)(read); if (p == "\n".ToCharArray()[0]) { if (plainBuf.EndsWith("\r")) plainBuf.Remove(plainBuf.LastIndexOf("\r")); if (!string.IsNullOrEmpty(plainBuf)) plain.Add(plainBuf); plainBuf = ""; } else plainBuf += p; } } stream.Close(); if (!string.IsNullOrEmpty(plainBuf)) plain.Add(plainBuf); return plain.ToArray(); }
public static void AppendText(string path, string text) { FileStream stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite); if (stream.ReadByte() == 0) { RC4Encryption enc = new RC4Encryption(Config.I.FilePassword); for (int x = 0; x < stream.Length; x++) enc.NextByte(); stream.Seek(0, SeekOrigin.End); for (int x = 0; x < text.Length; x++) { stream.WriteByte((byte)(text[x] ^ enc.NextByte())); } } else { stream.Seek(0, SeekOrigin.End); for (int x = 0; x < text.Length; x++) { stream.WriteByte((byte)(text[x])); } } stream.Close(); }
public static void WriteAllText(string path, string text) { if (Config.I.EncryptFiles) { FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write); stream.WriteByte(0); RC4Encryption enc = new RC4Encryption(Config.I.FilePassword); for (int x = 0; x < text.Length; x++) { stream.WriteByte((byte)(text[x] ^ enc.NextByte())); } stream.Close(); } else { FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write); for (int x = 0; x < text.Length; x++) { stream.WriteByte((byte)(text[x])); } stream.Close(); } }
public static string[] ReadAllLines(string path) { List <string> plain = new List <string>(); string plainBuf = ""; FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); if (stream.ReadByte() == 0) { //Encrypted RC4Encryption enc = new RC4Encryption(Config.I.FilePassword); int read = 0; while (read != -1 && stream.Position < stream.Length) { read = stream.ReadByte(); char p = (char)(read ^ enc.NextByte()); if (p == "\n".ToCharArray()[0]) { if (plainBuf.EndsWith("\r")) { plainBuf.Remove(plainBuf.LastIndexOf("\r")); } if (!string.IsNullOrEmpty(plainBuf)) { plain.Add(plainBuf); } plainBuf = ""; } else { plainBuf += p; } } } else { //Plain stream.Seek(0, SeekOrigin.Begin); int read = 0; while (read != -1 && stream.Position < stream.Length) { read = stream.ReadByte(); char p = (char)(read); if (p == "\n".ToCharArray()[0]) { if (plainBuf.EndsWith("\r")) { plainBuf.Remove(plainBuf.LastIndexOf("\r")); } if (!string.IsNullOrEmpty(plainBuf)) { plain.Add(plainBuf); } plainBuf = ""; } else { plainBuf += p; } } } stream.Close(); if (!string.IsNullOrEmpty(plainBuf)) { plain.Add(plainBuf); } return(plain.ToArray()); }
public static string ReadAllText(string path) { string plain = ""; FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read); stream.Seek(0, SeekOrigin.Begin); if (stream.ReadByte() == 0) { //Encrypted RC4Encryption enc = new RC4Encryption(Config.I.FilePassword); int read = 0; while (read != -1 && stream.Position < stream.Length) { read = stream.ReadByte(); plain += (char)(read ^ enc.NextByte()); } } else { //Plain int read = 0; stream.Seek(0, SeekOrigin.Begin); while (read != -1 && stream.Position < stream.Length) { read = stream.ReadByte(); plain += (char)read; } } stream.Close(); return plain; }