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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:43:47+00:00 2026-05-10T15:43:47+00:00

I’m trying to store a password in a file that I’d like to retrieve

  • 0

I’m trying to store a password in a file that I’d like to retrieve for later. Hashing is not an option as I need the password for connecting to a remote server for later.

The following code works well, but it creates a different output each time even though the key is the same. This is bad as when the application shuts down and restarts I won’t be able to retrieve my password any more. How can I store passwords in a file and retrieve them later?

public class EncyptDecrypt {      static System.Security.Cryptography.TripleDESCryptoServiceProvider keyProv = new System.Security.Cryptography.TripleDESCryptoServiceProvider();      public static System.Security.Cryptography.TripleDESCryptoServiceProvider KeyProvider {         get {             keyProv.Key = new byte[] { /* redacted with prejudice */ };             return keyProv;         }     }      public static string Encrypt(string text, SymmetricAlgorithm key) {          if (text.Equals(string.Empty)) return text;          // Create a memory stream.         MemoryStream ms = new MemoryStream();          // Create a CryptoStream using the memory stream and the         // CSP DES key.         CryptoStream encStream = new CryptoStream(ms, key.CreateEncryptor(), CryptoStreamMode.Write);          // Create a StreamWriter to write a string         // to the stream.         StreamWriter sw = new StreamWriter(encStream);          // Write the plaintext to the stream.         sw.WriteLine(text);          // Close the StreamWriter and CryptoStream.         sw.Close();         encStream.Close();          // Get an array of bytes that represents         // the memory stream.         byte[] buffer = ms.ToArray();          // Close the memory stream.         ms.Close();          // Return the encrypted byte array.         return System.Convert.ToBase64String(buffer);     }      // Decrypt the byte array.     public static string Decrypt(string cypherText, SymmetricAlgorithm key) {          if (cypherText.Equals(string.Empty)) return cypherText;          string val;          try {             // Create a memory stream to the passed buffer.             MemoryStream ms = new MemoryStream(System.Convert.FromBase64String(cypherText));              // Create a CryptoStream using the memory stream and the             // CSP DES key.             CryptoStream encStream = new CryptoStream(ms, key.CreateDecryptor(), CryptoStreamMode.Read);              // Create a StreamReader for reading the stream.             StreamReader sr = new StreamReader(encStream);              // Read the stream as a string.             val = sr.ReadLine();              // Close the streams.             sr.Close();             encStream.Close();             ms.Close();         }         catch (System.Exception) {              return string.Empty;         }          return val;     } } 
  • 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. 2026-05-10T15:43:48+00:00Added an answer on May 10, 2026 at 3:43 pm

    I believe that what’s happening is that the crypto provider is randomly generating an IV. Specify this and it should no longer differ.

    Edit: You can do this in your ‘keyProvider’ by setting the IV property.

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

Sidebar

Related Questions

I am trying to render a haml file in a javascript response like so:
I need a function that will clean a strings' special characters. I do NOT
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) 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.