-5

I am working on a "Kill Switch" program in C# where if I do not verify in the software within a time limit it will encrypt all of my files using B64(I will make my own algorithm later on) but currently there is a error where the software does not encrypt all lines of code, it only encrypts the first line and then deletes the rest. Any ideas?

Code:

foreach (string fileName in Directory.GetFiles("D:/Desktop/encTest"))
{
    string msg = "";

    using (StreamReader sr = new StreamReader(fileName))
    {
        msg = Base64StringEncode(sr.ReadLine());
    }

    string docPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

    using (StreamWriter outputFile = new StreamWriter(Path.Combine(docPath, fileName)))
    {
        outputFile.WriteLine(msg);
    }
}

I also have a function for B64 encryption!

General Grievance
  • 4,555
  • 31
  • 31
  • 45
Beemo
  • 41
  • 4
  • 4
    Well yeah, you're only calling `ReadLine()` once for each file. Why not use `File.ReadAllText()`? – gunr2171 May 17 '21 at 15:34
  • 2
    Also, base 64 encoding is NOT encryption. – gunr2171 May 17 '21 at 15:36
  • Duplicate linked above is specifically adressing large file sizes, but I think you'll find that using CryptoStream + ToBase64Transform makes it easier to refactor to use an actual encryption algorithm in the future – Mathias R. Jessen May 17 '21 at 15:37
  • 1
    in addition to gunr's comment: ***DO NOT EVER*** make your own encryption algorithm unless you know ***exactly*** what you are doing, and have a degree to prove it. _thank you_. also: seems more like potential malware. – Franz Gleichmann May 17 '21 at 15:37
  • Franz Gleichmann It is not malware. I am making my own personal project for fun and I will not distribute any of it – Beemo May 17 '21 at 15:38
  • 2
    @Beemo that's why i used the word "potential". – Franz Gleichmann May 17 '21 at 15:39
  • 3
    Before you study encryption, you need to study [how to debug](https://idownvotedbecau.se/nodebugging/). – Dour High Arch May 17 '21 at 15:49

1 Answers1

-1

You do not have a loop anywhere. It sets msg variable to the encrypted equivalent of your first line in the input file.

You need to implement a loop for that if you want to do it line by line.

HugoHiasl
  • 314
  • 2
  • 15