[C#]File Encryptor

Results 1 to 3 of 3
  1. #1
    (oO (||||) (||||) Oo) jM2.me is offline
    MemberRank
    Aug 2009 Join Date
    USA (Fuck Yeah)Location
    2,527Posts

    happy [C#]File Encryptor

    Tool that lets you encrypt&decrypt a file.

    Basically major code is below, but feel free to download full source and compile it.

    Code:
    private void button1_Click(object sender, EventArgs e)
            {
                OpenFileDialog xOpen = new OpenFileDialog();
                SaveFileDialog xSave = new SaveFileDialog();
                
                xOpen.Title = "Select File to Encrypt/Decrypt";
                if (xOpen.ShowDialog() == DialogResult.OK)
                {
                    if (xSave.ShowDialog() == DialogResult.OK)
                    {
                        SaveFile(xSave.FileName, EncryptBytes(OpenFile(xOpen.FileName), 0xDC));
                    }
                }
            }
            public byte[] EncryptBytes(byte[] input, byte xorKey)
            {
                byte[] output = new byte[input.Length];
                for (int i = 0; i < input.Length; i++)
                {
                    output[i] = (byte)(input[i]^xorKey);
                    xorKey ^= (byte)((input.Length - 1) + i);
                }
                return output;
            }
            public byte[] OpenFile(string filePath)
            {
                FileStream openFile = File.OpenRead(filePath);
                byte[] inputFile = new byte[openFile.Length];
                openFile.Read(inputFile, 0, (int)openFile.Length);
                openFile.Close();
                return inputFile;
            }
            public void SaveFile(string filePath, byte[] fileContent)
            {
                FileStream saveFile = new FileStream(filePath, FileMode.Create, FileAccess.Write);
                saveFile.Write(fileContent, 0, (int)fileContent.Length);
                saveFile.Close();
            }

    P.S. This is my first product after learning about XOR
    Attached Files Attached Files


  2. #2
    Pika? PIKA?!?! heartbeat is offline
    MemberRank
    Sep 2009 Join Date
    United KingdomLocation
    309Posts

    Re: [C#]File Encryptor

    would be more smexy with a hawter UI ;]

    maybe incorporate a custom salt/encryption key?

  3. #3
    Extreme Coder - Delphi bounty-hunter is offline
    MemberRank
    Sep 2007 Join Date
    GunZone MansionLocation
    1,725Posts

    Re: [C#]File Encryptor

    Done something like this in the pass, using XOR and Delphi



Advertisement