T
theinsanecoder
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.BaseStream,
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.BaseStream,
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?
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.BaseStream,
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.BaseStream,
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?