Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8658705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:50:02+00:00 2026-06-12T15:50:02+00:00

I have an existing zip file, I want to use AESManaged class to encrypt

  • 0

I have an existing zip file, I want to use AESManaged class to encrypt it, but I don’t find where I can set the password to the zip file in that class. After researching, I found some libaries such as ‘DotNetZip’ can complete the task. But my file is already a .zip, I needn’t to compress again, I only want to encrypt it. Anyone can help me to use AESManaged class to ahieve the purpose?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:50:03+00:00Added an answer on June 12, 2026 at 3:50 pm

    I don’t know if this is what your are looking for but I created a code that encrypts any file.

    Here’s the code for the encrypter:

    private void EncryptFile(string inputFile, string outputFile)
            {
                string password = @"yourPWhere";
                UnicodeEncoding UE = new UnicodeEncoding();
                byte[] key = CreateKey(password);
    
                string cryptFile = outputFile;
                FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);
    
                RijndaelManaged RMCrypto = new RijndaelManaged();
                IV = CreateIV(password_mTxtBx.Text);
    
                CryptoStream cs = new CryptoStream(fsCrypt,
                    RMCrypto.CreateEncryptor(key,IV),
                    CryptoStreamMode.Write);
    
                FileStream fsIn = new FileStream(inputFile, FileMode.Open);
    
                int data;
                while ((data = fsIn.ReadByte()) != -1)
                    cs.WriteByte((byte)data);
    
    
                fsIn.Close();
                cs.Close();
                fsCrypt.Close();
            }
    

    Here’s the code for the decrypter:

            private void DecryptFile(string inputFile, string outputFile)
        {
                string password = @"yourPWhere";
    
                UnicodeEncoding UE = new UnicodeEncoding();
                byte[] key = CreateKey(password);
                FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);
                RijndaelManaged RMCrypto = new RijndaelManaged();
                IV = CreateIV(password_mTxtBx.Text);
    
                CryptoStream cs = new CryptoStream(fsCrypt,
                    RMCrypto.CreateDecryptor(key, IV),
                    CryptoStreamMode.Read);
    
                FileStream fsOut = new FileStream(outputFile.Remove(outputFile.Length - 4), FileMode.Create);
    
                int data;
                while ((data = cs.ReadByte()) != -1)
                    fsOut.WriteByte((byte)data);
    
                fsOut.Close();
                cs.Close();
                fsCrypt.Close();
    
            }
    

    I saw a similar code on codeproject a few months ago. So it’s not directly my work.
    Credits go to the author.

    Updated with password-based key derivation (PBKDF2):

    private static int saltLengthLimit = 32;
    private static byte[] GetSalt(int maximumSaltLength)
    {
        var salt = new byte[maximumSaltLength];
        using (var random = new RNGCryptoServiceProvider())
        {
            random.GetNonZeroBytes(salt);
        }
    
        return salt;
    }
    public static byte[] CreateKey(string password)
    {
        var salt = GetSalt(10);
    
        int iterationCount = 20000; // Nowadays you should use at least 10.000 iterations
        using (var rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, salt, iterationCount))
            return rfc2898DeriveBytes.GetBytes(16);
    }
    

    Creator for the IV (created from Password):

    public byte[] CreateIV(string password)
    {
        var salt = GetSalt(9);
    
        const int Iterations = 325;
        using (var rfc2898DeriveBytes = new Rfc2898DeriveBytes(password, salt, Iterations))
            return rfc2898DeriveBytes.GetBytes(16);
    }
    

    The byte length of the key is in my case 128bit(!) = 16 bytes (128/8), but you can use any other length supported by Rijndael (Key: 128, 192, 256 bit = 16, 24, 32 bytes).
    The IV is always 16 bytes!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing ZIP file (with some files) where I want to add
I have existing code that uses CMNewProfileSearch to find then iterate over the color
I have existing Linux shared object file (shared library) which has been stripped. I
I have existing code with their own makefiles which I want to load into
I have an existing web service and I want it to expose 2 MEX
I have attempted to find a way to create a zip archive (or GZip
I am using OLEDB to INSERT INTO an existing Excel worksheet. But I want
Using TrueZIP, is there a way to open and modify an existing ZIP file
I have content to be installed, but it's file and folder layout is determined
I have a zip file which I have to extract information from which I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.