[quoted text, click to view] EMW <SomeOne@MicroSoftdotCom> wrote:
<snip> [quoted text, click to view] > In the sub where I call these function I use: > ds.writexml(Cryptowriter(filename)) > to write the tables from the dataset to disk. > I don't get any errors and a nicely unreadable file. > > When I use: > ds.readxml(cryptoreader(filename)) > to read the xml back and in the dataset I get the following error: > > System.Security.Cryptography.CryptographicException: PKCS7.... > > Can someone help me with this? > All I want to do is to read the encrypted xml file in to a dataset, do > something with it, then encrypt it again and write it to disk.
You haven't shown the streams being closed - and unless they're closed, the final block might not be getting flushed, which would lead to an invalid decryption stream. -- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet
Hi, I use the following code: Function CryptoWriter(ByVal file As String) As CryptoStream Dim FileWriter As FileStream = New FileStream(file, FileMode.Create) Dim CryptoProvider As RijndaelManaged = New RijndaelManaged Dim key As Byte() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} Dim iv As Byte() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} Return New CryptoStream(FileWriter, CryptoProvider.CreateEncryptor(key, iv), CryptoStreamMode.Write) End Function Function CryptoReader(ByVal file As String) As CryptoStream Dim FileReader As FileStream = New FileStream(file, FileMode.Open) Dim CryptoProvider As RijndaelManaged = New RijndaelManaged Dim key As Byte() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} Dim iv As Byte() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} Return New CryptoStream(FileReader, CryptoProvider.CreateDecryptor(key, iv), CryptoStreamMode.Read) End Function In the sub where I call these function I use: ds.writexml(Cryptowriter(filename)) to write the tables from the dataset to disk. I don't get any errors and a nicely unreadable file. When I use: ds.readxml(cryptoreader(filename)) to read the xml back and in the dataset I get the following error: System.Security.Cryptography.CryptographicException: PKCS7.... Can someone help me with this? All I want to do is to read the encrypted xml file in to a dataset, do something with it, then encrypt it again and write it to disk. thanks, Eric
How dso I close them, since I pass the stream on from a function? rg, Eric "Jon Skeet [C# MVP]" <skeet@pobox.com> schreef in bericht news:MPG.1b3c1bc29169584998acd5@msnews.microsoft.com... [quoted text, click to view] > EMW <SomeOne@MicroSoftdotCom> wrote: > > <snip> > > > In the sub where I call these function I use: > > ds.writexml(Cryptowriter(filename)) > > to write the tables from the dataset to disk. > > I don't get any errors and a nicely unreadable file. > > > > When I use: > > ds.readxml(cryptoreader(filename)) > > to read the xml back and in the dataset I get the following error: > > > > System.Security.Cryptography.CryptographicException: PKCS7.... > > > > Can someone help me with this? > > All I want to do is to read the encrypted xml file in to a dataset, do > > something with it, then encrypt it again and write it to disk. > > You haven't shown the streams being closed - and unless they're closed, > the final block might not be getting flushed, which would lead to an > invalid decryption stream. > > -- > Jon Skeet - <skeet@pobox.com> > http://www.pobox.com/~skeet > If replying to the group, please do not mail me too
[quoted text, click to view] EMW <SomeOne@MicroSoftdotCom> wrote: > How dso I close them, since I pass the stream on from a function?
The answer is not to pass the stream immediately. Instead, do: Stream stream = CryptoWriter(filename); ds.WriteXml(stream); stream.Close(); (You should put it in a suitable try/finally block so that the stream gets closed even if an exception is thrown.) -- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet
ok, thanks! "Jon Skeet [C# MVP]" <skeet@pobox.com> schreef in bericht news:MPG.1b3ca0b39913359598acd7@msnews.microsoft.com... [quoted text, click to view] > EMW <SomeOne@MicroSoftdotCom> wrote: > > How dso I close them, since I pass the stream on from a function? > > The answer is not to pass the stream immediately. Instead, do: > > Stream stream = CryptoWriter(filename); > ds.WriteXml(stream); > stream.Close(); > > (You should put it in a suitable try/finally block so that the stream > gets closed even if an exception is thrown.) > > -- > Jon Skeet - <skeet@pobox.com> > http://www.pobox.com/~skeet > If replying to the group, please do not mail me too
Don't see what you're looking for? Try a search.
|