473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Using cryptographic streams with XML

Hi, i'm using the xmlserializer to load and unload data from my files
but i want to crypt them using a not so secure cryptographic encoder.
My code to encrypt "seems" to work fine, the file is outputted but when
i import the file again using the same concept (but in reversed form) i
get XMLDocument is invalid (1, 1) exception thrown back at me. Here is
the code :

SAVING PORTION

'Save the game
Dim oXS As XmlSerializer = New
XmlSerializer(GetType(Game.Game))
Dim oStmW As StreamWriter
Dim oXmlW As XmlTextWriter

'Setup the stream writer
oStmW = New StreamWriter(pFilename)

'Setup cryptographic stream cypher
Dim CryptoAlgo As New DESCryptoServiceProvider()
Dim Cryptographer As
System.Security.Cryptography.CryptoStream
CryptoAlgo.BlockSize = 64
CryptoAlgo.KeySize = 64
Cryptographer = New
System.Security.Cryptography.CryptoStream(oStmW.Ba seStream,
CryptoAlgo.CreateEncryptor(KEY_8, IV_8), CryptoStreamMode.Write)

'Setup the text writer with cryptostream instead of
original stream (Crypto will link them)
oXmlW = New XmlTextWriter(Cryptographer, New
System.Text.UTF8Encoding())

'Execute the write
oXS.Serialize(oXmlW, Game)
oXmlW.Close()

LOADING PORTION

'Load the new game
Dim oXS As XmlSerializer = New
XmlSerializer(GetType(Game.Game))
Dim oStmR As StreamReader
Dim oXmlR As XmlTextReader

'Setup the stream reader
oStmR = New StreamReader(pFilename)

'Setup cryptographic stream cypher
Dim CryptoAlgo As New DESCryptoServiceProvider()
Dim Cryptographer As
System.Security.Cryptography.CryptoStream
CryptoAlgo.BlockSize = 64
CryptoAlgo.KeySize = 64
Cryptographer = New
System.Security.Cryptography.CryptoStream(oStmR.Ba seStream,
CryptoAlgo.CreateEncryptor(KEY_8, IV_8), CryptoStreamMode.Read)

'Setup the text reader with cryptostream instead of
original stream (Crypto will link them)
oXmlR = New XmlTextReader(Cryptographer)

'Execute the read
oXmlR.WhitespaceHandling =
WhitespaceHandling.Significant
Game = oXS.Deserialize(oXmlR)
oXmlR.Close()

Like said earlier, SAVING seems to work fine and outputs a file that is
encrypted when i open it from notepad, but i may be wrong, maybe it's
just outputting rubish. The Load definitely doesn't work throwing back
an InvalidOperationException with the following content, "There is an
error in the XML document (1, 1)"

Can anyone help please?

Sep 24 '06 #1
2 2073
Try not using the xmlwriter for the encrypted output. Just use the
xmlreader for the unencrypted input. Mind you, I'm no expert on xml nor
cryptography, but purely from a logical perspective, the . It's worth a
shot.

Tom

th************@gmail.com wrote:
>Hi, i'm using the xmlserializer to load and unload data from my files
but i want to crypt them using a not so secure cryptographic encoder.
My code to encrypt "seems" to work fine, the file is outputted but when
i import the file again using the same concept (but in reversed form) i
get XMLDocument is invalid (1, 1) exception thrown back at me. Here is
the code :

SAVING PORTION

'Save the game
Dim oXS As XmlSerializer = New
XmlSerializer(GetType(Game.Game))
Dim oStmW As StreamWriter
Dim oXmlW As XmlTextWriter

'Setup the stream writer
oStmW = New StreamWriter(pFilename)

'Setup cryptographic stream cypher
Dim CryptoAlgo As New DESCryptoServiceProvider()
Dim Cryptographer As
System.Security.Cryptography.CryptoStream
CryptoAlgo.BlockSize = 64
CryptoAlgo.KeySize = 64
Cryptographer = New
System.Security.Cryptography.CryptoStream(oStmW.B aseStream,
CryptoAlgo.CreateEncryptor(KEY_8, IV_8), CryptoStreamMode.Write)

'Setup the text writer with cryptostream instead of
original stream (Crypto will link them)
oXmlW = New XmlTextWriter(Cryptographer, New
System.Text.UTF8Encoding())

'Execute the write
oXS.Serialize(oXmlW, Game)
oXmlW.Close()

LOADING PORTION

'Load the new game
Dim oXS As XmlSerializer = New
XmlSerializer(GetType(Game.Game))
Dim oStmR As StreamReader
Dim oXmlR As XmlTextReader

'Setup the stream reader
oStmR = New StreamReader(pFilename)

'Setup cryptographic stream cypher
Dim CryptoAlgo As New DESCryptoServiceProvider()
Dim Cryptographer As
System.Security.Cryptography.CryptoStream
CryptoAlgo.BlockSize = 64
CryptoAlgo.KeySize = 64
Cryptographer = New
System.Security.Cryptography.CryptoStream(oStmR.B aseStream,
CryptoAlgo.CreateEncryptor(KEY_8, IV_8), CryptoStreamMode.Read)

'Setup the text reader with cryptostream instead of
original stream (Crypto will link them)
oXmlR = New XmlTextReader(Cryptographer)

'Execute the read
oXmlR.WhitespaceHandling =
WhitespaceHandling.Significant
Game = oXS.Deserialize(oXmlR)
oXmlR.Close()

Like said earlier, SAVING seems to work fine and outputs a file that is
encrypted when i open it from notepad, but i may be wrong, maybe it's
just outputting rubish. The Load definitely doesn't work throwing back
an InvalidOperationException with the following content, "There is an
error in the XML document (1, 1)"

Can anyone help please?
Sep 24 '06 #2
Problem is if i don't use an XML reader or XML Writer i can't keep the
line feeds in my descriptive texts. I'd have to provide some complex
HTML content which would output <BR>s insteads of vbCrLfs... Unless you
klnow of a solution to bypass the line feeding problem i have to keep
the text reader/writer...

Sep 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: ferran | last post by:
Hi, I'm trying to convert a string to a long double using streams but for some reasing seems to give the wrong values, the idea is to do a precise textual conversion without roundings or...
3
by: Tron Thomas | last post by:
What does binary mode for an ofstream object do anyway? Despite which mode the stream uses, operator << writes numeric value as their ASCII representation. I read on the Internet that it is...
6
by: radnoraj | last post by:
Hi, I am sucessfull in redirecting console output to a file. but in this case nothing is displayed on the console, cout output is written to file without display. how do write the output to...
32
by: David Garamond | last post by:
Are there any drawbacks of using BYTEA for PK compared to using a primitive/atomic data types like INT/SERIAL? (like significant performance hit, peculiar FK behaviour, etc). I plan to use BYTEA...
47
by: Bonj | last post by:
I downloaded the gzlib library from zlib in order to do compression. (http://www.gzip.org/zlib) The prototype of the compression function seems to be int compress (Bytef *dest, uLongf *destLen,...
2
by: fineman | last post by:
Hi all, I want to get a 64bit(8 bytes) Encrypt result use DES class in the VS2005. Though I encrypt data is 64bit(8 bytes), but DES return encrypt result that always is 128bit(16 bytes), I don't...
1
by: =?Utf-8?B?c3VyZmtlaXRo?= | last post by:
A machine running XP Home fails to start the cryptographic service. When attempting to start from the services menu it responds with error 2: the file specified cannot be found. I am unable to...
1
by: lide.wyb | last post by:
We are using only the OpenSSL cryptographic functionality, the EVP and HMAC functions, in a multi-threaded application. Do we need to do anything to ensure thread safety ? The documentation...
17
by: almurph | last post by:
Hi, Hope you can help me with this one. I am trying to create random number between 0 and 1 inclusive of cryptographiuc quality. The problems is though - I don't know how! Here is what I have so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.