|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using cryptographic streams with XMLbut 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? 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 theinsaneco***@gmail.com wrote: Show quoteHide quote >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? > > > 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...
UTF8 Encoding and MP3 tags
SQL Statement for limiting the number of detail retrieved in Access 2000? Use items from... SQL DISTINCT COUNT NullReferenceException Constant - InDebugMode Single Sign On / Authentication System? UserControls in a different directory Deploying programs with net framework 2 onto framework 1 What does instantText mean in Edit method of DataGridColumnStyle |
|||||||||||||||||||||||