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

  • Home
  • SEARCH
  • 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 378667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:49:00+00:00 2026-05-12T14:49:00+00:00

Really not having a good week with encryption. Let me explain what I need.

  • 0

Really not having a good week with encryption. Let me explain what I need.

  1. I want to encrypt string values to a file….
  2. I want to decrypt the file contents back to a string using C#
  3. I want to do this without having to worry about machine store or user store or any other store, neither a registry , etc.
  4. Any security key can be shipped in my application.

security doesn’t have to be remarkably strong, and my code is obfuscated.

I just want a solution that is portable. I’ve tried RSA and it got me nowhere fast after finding out that in production a certain key file is missing, something I know nothing about and can’t locate it on the dev machine.

Please help.

  • 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-12T14:49:01+00:00Added an answer on May 12, 2026 at 2:49 pm

    Here is some code that I use quite a bit (adapted it from source on the web) which relies solely on a passphrase stored in web.config/app.config under setttings. It uses triple des.

     /// <summary>
            /// Encrypts the string.
            /// </summary>
            /// <param name="text">The text.</param>
            /// <returns>Encrypted string</returns>
            public string EncryptString(string text)
            {
                // Locals
                var passphrase = ConfigurationManager.AppSettings["Your Encrypt Passphrase"];
                byte[] results;
                var utf8 = new UTF8Encoding();
    
                // Step 1. We hash the passphrase using MD5
                // We use the MD5 hash generator as the result is a 128 bit byte array
                // which is a valid length for the TripleDES encoder we use below
                var hashProvider = new MD5CryptoServiceProvider();
                var tdesKey = hashProvider.ComputeHash(utf8.GetBytes(passphrase));
    
                // Step 2. Create a new TripleDESCryptoServiceProvider object
                // Step 3. Setup the encoder
                var tdesAlgorithm = new TripleDESCryptoServiceProvider
                                        {
                                            Key = tdesKey,
                                            Mode = CipherMode.ECB,
                                            Padding = PaddingMode.PKCS7
                                        };
    
                // Step 4. Convert the input string to a byte[]
                var dataToEncrypt = utf8.GetBytes(text);
    
                // Step 5. Attempt to encrypt the string
                try
                {
                    var encryptor = tdesAlgorithm.CreateEncryptor();
                    results = encryptor.TransformFinalBlock(dataToEncrypt, 0, dataToEncrypt.Length);
                }
                finally
                {
                    // Clear the TripleDes and Hashprovider services of any sensitive information
                    tdesAlgorithm.Clear();
                    hashProvider.Clear();
                }
    
                // Step 6. Return the encrypted string as a base64 encoded string
                return Convert.ToBase64String(results);
            }
    
            /// <summary>
            /// Decrypts the string.
            /// </summary>
            /// <param name="text">The text.</param>
            /// <returns>Decrypted string</returns>
            public string DecryptString(string text)
            {
                // Locals
                var passphrase = ConfigurationManager.AppSettings["Your Encrypt Passphrase"];
                byte[] results;
                var utf8 = new UTF8Encoding();
    
                // Step 1. We hash the passphrase using MD5
                // We use the MD5 hash generator as the result is a 128 bit byte array
                // which is a valid length for the TripleDES encoder we use below
                var hashProvider = new MD5CryptoServiceProvider();
                var tdesKey = hashProvider.ComputeHash(utf8.GetBytes(passphrase));
    
                // Step 2. Create a new TripleDESCryptoServiceProvider object
                // Step 3. Setup the decoder
                var tdesAlgorithm = new TripleDESCryptoServiceProvider
                                        {
                                            Key = tdesKey,
                                            Mode = CipherMode.ECB,
                                            Padding = PaddingMode.PKCS7
                                        };
    
                // Step 4. Convert the input string to a byte[]
                var dataToDecrypt = Convert.FromBase64String(text);
    
                // Step 5. Attempt to decrypt the string
                try
                {
                    var decryptor = tdesAlgorithm.CreateDecryptor();
                    results = decryptor.TransformFinalBlock(dataToDecrypt, 0, dataToDecrypt.Length);
                }
                finally
                {
                    // Clear the TripleDes and Hashprovider services of any sensitive information
                    tdesAlgorithm.Clear();
                    hashProvider.Clear();
                }
    
                // Step 6. Return the decrypted string in UTF8 format
                return utf8.GetString(results);
            }
    

    The original source was here: http://www.dijksterhuis.org/encrypting-decrypting-string/

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Objective-C is a strict superset of C, therefore you can… May 13, 2026 at 8:02 pm
  • Editorial Team
    Editorial Team added an answer textbox= new EditField(" ","",500,EditField.NO_NEWLINE | Field.FOCUSABLE) { protected void paint(Graphics… May 13, 2026 at 8:02 pm
  • Editorial Team
    Editorial Team added an answer time.strptime returns a time_struct; time.strftime accepts a time_struct as an… May 13, 2026 at 8:02 pm

Related Questions

Does anyone know of a good software development framework or similar that has the
Not having a really great time with the smart template projects found on CodePlex.
Ok, I have looked all over and I am having a difficult time trying
We have a software product that evolves at the rhythm of clients' needs and

Trending Tags

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

Top Members

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.