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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:24:22+00:00 2026-06-03T13:24:22+00:00

I need to write XML data to an encrypted file. I can read/write encrypted

  • 0

I need to write XML data to an encrypted file. I can read/write encrypted files, but I am having trouble figuring out how to skip the file input part and do it from a MemoryStream object.

This is what I have so far. Basically I just need to get a Byte[] to preform my standard encryption on it.

I appreciate the awesome input. I will be testing this shortly.

EDIT: After testing I am getting a “Cannot access a closed stream” exception when I try and close the memorystream object.

MemoryStream ms = new MemoryStream();
XmlTextWriter xmlwriter = new XmlTextWriter(ms,Encoding.ASCII);
FileStream EncryptedFileStream = new FileStream(file, FileMode.Create, FileAccess.Write);

DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
DES.Key = ASCIIEncoding.ASCII.GetBytes("AAAAAAAA");
DES.IV = ASCIIEncoding.ASCII.GetBytes("AAAAAAAA");

ICryptoTransform desEncrypt = DES.CreateEncryptor();
CryptoStream cryptostream = new CryptoStream(EncryptedFileStream, desEncrypt, CryptoStreamMode.Write);

//create xml document

byte[] bytearray = new byte[ms.Length];
ms.Read(bytearray, 0, bytearray.Length);

cryptostream.Write(bytearray, 0, bytearray.Length);

cryptostream.Close();
ms.Close();
EncryptedFileStream.Close();
  • 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-03T13:24:31+00:00Added an answer on June 3, 2026 at 1:24 pm

    Write into a MemoryStream and use MemoryStream.ToArray()

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

Sidebar

Related Questions

I need to write model data ( CharField s only) to an XML file
I need a way to store data inside xml files and write to differant
I need to generate an XML file in C#. I want to write the
I need to write a XML-based markup language. I'd like to provide an open
I need to write an XML schema that accept XMLs such as: <?xml version=1.0
First of all: What I need to achieve is write an Xml document Header,
I'm trying to write a Linq2XML query to query the following XML. I need
I need to write a regular expression to verify if a file input follows
I need to write the contents of a js file from a convention-driven location
I am playing around with saving .xml files from data in my game. 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.