Hi guys im creating this cryptography program. And was wondering how to connect three conditions together.
*Forgot to mention it is in c# language*
I got a place where i can input a key and confirm the key, Those are already linked together when u click the encrypt button it will verify that both text areas are equivalent.
A combobox to choose the type of encryption &
The Encrypt buton to give the order to encrypt

I dont know how to go about and connect everything together. Can someone help me please?

I do have the code for the encryption and the types of encryption and implementation techniques. All i have to do is connect those 3 things together. I could have very well chose for for every one to open in a new form but i dont like the idea.

Anyways, Thanks in advance!
And if you want more info on the code just ask me and ill write back to ya!

Dani AI

Generated

Building on 's UI-selection idea: the Encrypt button should validate the entered key, pick the chosen algorithm, then call a single encrypting routine that does the I/O and cryptography off the UI thread. A reliable pipeline is: validate/confirm the password, derive a strong key+IV from the password (PBKDF2), generate a random salt and IV, read the input file as bytes, encrypt those bytes with the chosen algorithm, and write an output file that begins with the salt and IV so the file can be decrypted later.

Example C# pipeline (call from a background task so the UI stays responsive):

public void EncryptFile(string inPath, string outPath, string password)
{
    byte[] salt = new byte[16];
    using (var rng = new RNGCryptoServiceProvider()) rng.GetBytes(salt);

    using (var kdf = new Rfc2898DeriveBytes(password, salt, 100_000))
    {
        byte[] key = kdf.GetBytes(32); // AES-256
        byte[] iv  = kdf.GetBytes(16);

        using (var aes = Aes.Create())
        using (var inFs = File.OpenRead(inPath))
        using (var outFs = File.Create(outPath))
        {
            outFs.Write(salt, 0, salt.Length);
            outFs.Write(iv,   0, iv.Length);

            using (var crypto = new CryptoStream(outFs, aes.CreateEncryptor(key, iv), CryptoStreamMode.Write))
            {
                inFs.CopyTo(crypto);
            }
        }
    }
}

Troubleshooting and cautions: ensure decryption uses the same salt, iteration count, and KDF parameters. Check key lengths and algorithm choices match expected sizes. Prefer authenticated modes (AES-GCM or HMAC) to detect tampering; .NET newer APIs expose AesGcm. Clear sensitive buffers/SecureString where feasible. For long runs, report progress by copying in buffered chunks and updating a progress callback. For authoritative guidance on PBKDF2 and AES usage, see Microsoft's cryptography docs: Rfc2898DeriveBytes and Aes.

Recommended Answers

All 2 Replies

There are several ways to do that, I would go about it this way:

// the encrypt button event handler
encrypt_Click(object sender, EventArgs e)
{
    // assuming you've named the text box for the key txtKey and the
    // combo box for the encryption type cboEnc do the following
    string key = txtKey.Text;
    string encType = cboEnc.SelectedItem.ToString();
    switch(encType)
    {
          case "FirstEncryptionType":
               // use this encryption;
               break;
          case "SecondEncryptionType":
               // use this encryption
               break;
          default:
               // use the final incryption type
               break;
       }
}

So maybe I'm not understandin your question properly. But that's how you could do, just use a switch statment to find out which encryption type to use, then do the statements from there.

WoW thats great!
Now i was able to add this part of the code in but how would i go about after chosing the encryption type and actually clicking the ENCRYPT button to actually encrypt the file opened... I do have the algorithm.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.