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.CryptographicExceptio n: 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