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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:32:50+00:00 2026-05-12T19:32:50+00:00

I have to encrypt/decrypt some sensitive information in a Xml file? Yes I can

  • 0

I have to encrypt/decrypt some sensitive information in a Xml file?
Yes I can do that by writing my own custom algorithms. I am wondering if there is already a built in way in .NET to do that and also what points I always need to take care..

  • 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-12T19:32:50+00:00Added an answer on May 12, 2026 at 7:32 pm

    Here’s a couple of functions that use the .NET framework to encrypt and decrypt a string:

    public string EncryptString(string plainText)
    {
        // Instantiate a new RijndaelManaged object to perform string symmetric encryption
        RijndaelManaged rijndaelCipher = new RijndaelManaged();
    
        // Set key and IV
        rijndaelCipher.Key = Convert.FromBase64String("ABC");
        rijndaelCipher.IV = Convert.FromBase64String("123");
    
        // Instantiate a new MemoryStream object to contain the encrypted bytes
        MemoryStream memoryStream = new MemoryStream();
    
        // Instantiate a new encryptor from our RijndaelManaged object
        ICryptoTransform rijndaelEncryptor = rijndaelCipher.CreateEncryptor();
    
        // Instantiate a new CryptoStream object to process the data and write it to the 
        // memory stream
        CryptoStream cryptoStream = new CryptoStream(memoryStream, rijndaelEncryptor, CryptoStreamMode.Write);
    
        // Convert the plainText string into a byte array
        byte[] plainBytes = Encoding.ASCII.GetBytes(plainText);
    
        // Encrypt the input plaintext string
        cryptoStream.Write(plainBytes, 0, plainBytes.Length);
    
        // Complete the encryption process
        cryptoStream.FlushFinalBlock();
    
        // Convert the encrypted data from a MemoryStream to a byte array
        byte[] cipherBytes = memoryStream.ToArray();
    
        // Close both the MemoryStream and the CryptoStream
        memoryStream.Close();
        cryptoStream.Close();
    
        // Convert the encrypted byte array to a base64 encoded string
        string cipherText = Convert.ToBase64String(cipherBytes, 0, cipherBytes.Length);
    
        // Return the encrypted data as a string
        return cipherText;
    }
    
    
    public string DecryptString(string cipherText)
    {
        // Instantiate a new RijndaelManaged object to perform string symmetric encryption
        RijndaelManaged rijndaelCipher = new RijndaelManaged();
    
        // Set key and IV
        rijndaelCipher.Key = Convert.FromBase64String("ABC");
        rijndaelCipher.IV = Convert.FromBase64String("123");
    
        // Instantiate a new MemoryStream object to contain the encrypted bytes
        MemoryStream memoryStream = new MemoryStream();
    
        // Instantiate a new encryptor from our RijndaelManaged object
        ICryptoTransform rijndaelDecryptor = rijndaelCipher.CreateDecryptor();
    
        // Instantiate a new CryptoStream object to process the data and write it to the 
        // memory stream
        CryptoStream cryptoStream = new CryptoStream(memoryStream, rijndaelDecryptor, CryptoStreamMode.Write);
    
        // Will contain decrypted plaintext
        string plainText = String.Empty;
    
        try
        {
            // Convert the ciphertext string into a byte array
            byte[] cipherBytes = Convert.FromBase64String(cipherText);
    
            // Decrypt the input ciphertext string
            cryptoStream.Write(cipherBytes, 0, cipherBytes.Length);
    
            // Complete the decryption process
            cryptoStream.FlushFinalBlock();
    
            // Convert the decrypted data from a MemoryStream to a byte array
            byte[] plainBytes = memoryStream.ToArray();
    
            // Convert the encrypted byte array to a base64 encoded string
            plainText = Encoding.ASCII.GetString(plainBytes, 0, plainBytes.Length);
        }
        finally
        {
            // Close both the MemoryStream and the CryptoStream
            memoryStream.Close();
            cryptoStream.Close();
        }
    
        // Return the encrypted data as a string
        return plainText;
    }
    

    Of course I don’t advise hardcoding the key and initialisation vector like this 🙂

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

Sidebar

Related Questions

We have a cookie management library that writes a cookie containing some sensitive information,
Is there a way to encrypt the data file that mysql uses? I have
I'm building a system that need to collect some user sensitive data via secured
I have some data in my user database that I would prefer to be
I have been trying to encrypt soap message and send to the server, so
I have a script that successfully encrypts a credit card. I need it to
I am looking into encrypting some sensitive data in SQL Server, such as bank
We have a requirement to do some Rijndael development in Java. Any recommendations for
I'm considering the following: I have some data stream which I'd like to protect
we have a project written in Delphi that we want to convert to C#.

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.