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 941711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:09:29+00:00 2026-05-15T22:09:29+00:00

This is a segment of code I have for setting the masterpassword: private void

  • 0

This is a segment of code I have for setting the masterpassword:

private void button1_Click(object sender, EventArgs e)
    {
        string current = textBox1.Text;
        string newPass = textBox2.Text;
        string confirmed = textBox3.Text;
        string massPass = "winxp.pma";


        if (File.Exists(massPass))
        {
            byte[] cipertext = File.ReadAllBytes(massPass);
            string decoded;
            if(Encryptor.TryDecrypt(current, cipertext, out decoded))
            {
                FileStream fs = new FileStream(massPass, FileMode.Truncate, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
                if(newPass == confirmed)
                {
                    byte[] newCipher = Encryptor.Encrypt(newPass, newPass);
                    string writeIt = System.Text.Encoding.UTF8.GetString(newCipher);
                    sw.Write(writeIt);
                    sw.Flush();
                    sw.Close();
                    fs.Close();
                    this.Close();

                }
                else
                {
                    MessageBox.Show("New password do not match.", "Error", MessageBoxButtons.OK);
                }

            }

        }
        else
        {
            FileStream fs = new FileStream(massPass, FileMode.Create, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
            if (newPass == confirmed)
            {
                byte[] ciphertext = Encryptor.Encrypt(newPass, newPass);
                string writeIt = System.Text.Encoding.UTF8.GetString(ciphertext);
                sw.Write(ciphertext);
                sw.Flush();
                sw.Close();
                fs.Close();
                this.Close();
            }

Back on the main form, I’m using the TryDecrypt method in the following manner:

private void S_Click(object sender, EventArgs e)
    {
        byte[] ciphertext = File.ReadAllBytes(massPass);
        string decoded;

            if (Encryptor.TryDecrypt(textBox1.Text, ciphertext, out decoded))
            {
                accountGroupsBox.Enabled = true;
                addNewPasswordToolStripMenuItem.Enabled = true;
                label2.Text = "Interface Unlocked";

            }
            else
            {
                MessageBox.Show("Incorrect Master Password.", "Authentication Error", MessageBoxButtons.OK);
            }

However, as I noted, it will not return true….I’m betting it something to do with the way I’m handling the FileStreams on the other form, but I dont understand enough whats happening under the hood to determine if I’m doing it correctly.

  • 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-05-15T22:09:30+00:00Added an answer on May 15, 2026 at 10:09 pm

    Your input stream isn’t complete. To be able to attempt to decrypt it, it must be a certain size. Ensure that your encryption process is correct. The encrypted data should be equal to or longer than your plain data.

    [edit]
    My conclusion back on the other site was that the CryptoStream did not have a chance to finish writing the data before your output file was closed. The output stream should remain open before the CryptoStream is disposed to be able to write the rest of the ciphertext and necessary padding.

    My test code:

    public static byte[] Encrypt(string password, string plaintext, SymmetricAlgorithm algorithm)
    {
        byte[] key, iv;
        CreateKeyIV(password, out key, out iv);
        using (MemoryStream encrypted = new MemoryStream())
        {
            using (CryptoStream enc = new CryptoStream(encrypted, algorithm.CreateEncryptor(key, iv), CryptoStreamMode.Write))
            using (StreamWriter writer = new StreamWriter(enc))
                writer.Write(plaintext);
            return encrypted.ToArray();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 497k
  • Answers 497k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Thanks for the reply but I found a very simple… May 16, 2026 at 11:54 am
  • Editorial Team
    Editorial Team added an answer You can return a helper object from function1 by value… May 16, 2026 at 11:54 am
  • Editorial Team
    Editorial Team added an answer I'm a little bit confused. First of all, you're saying… May 16, 2026 at 11:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have this code segment in which I am opening/closing a file a number
I have this segment of code , a lot of things skipped for brevity
I have a dropdown box that I construct with PHP. Here is the code:
I created a new project with the following code segment: char* strange = (Strange??);
How would you tackle this problem: I have data in my data store. Each
I have a configuration format similar to *.sln format, so take the following as
Note: This is not a problem i'm experiencing, but it is something i'd like
In my code I am using a UISegmentedControl as a button with only ONE
I would like to implement the Ramer–Douglas–Peucker_algorithm in C++. The pseudo code looks like
Are there any open-source tools or libraries for static code analysis of simple custom

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.