473,434 Members | 1,818 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,434 software developers and data experts.

XML en-/Decryption problem

EMW
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

Jul 21 '05 #1
4 1539
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.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.


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
EMW
How dso I close them, since I pass the stream on from a function?

rg,
Eric

"Jon Skeet [C# MVP]" <sk***@pobox.com> schreef in bericht
news:MP************************@msnews.microsoft.c om...
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.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.


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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3
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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #4
EMW
ok, thanks!
"Jon Skeet [C# MVP]" <sk***@pobox.com> schreef in bericht
news:MP************************@msnews.microsoft.c om...
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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #5

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

Similar topics

1
by: Jase H | last post by:
Hello, I have a ASP.NET web application problem involving the data encryption and decryption assembly(DLL) used on the connection string value that is set in the webconfig file. The problem...
1
by: Martin | last post by:
Hi Im trying to make a Client/Server where im going to encrypt the stream but i cant get it to work. I can recieve and send as long as im not trying to send/recieve encrypted. but when i am i cant...
2
by: almurph | last post by:
Hi everyone, Can you help me please? I am having a problem with the encryption/decryption of words with the Irish fada in them. The Irish fada is like this: áéíóú/ÁÉÍÓÚ. It's kind of like the...
0
by: Showjumper | last post by:
I solved my previous problem. The new one is that the password is not being decrypted but rather is still in the enrypted format. I am using Rijndael emcryption. Below is the decryption code. And...
9
by: DarkProtoman | last post by:
How would I write a function to calculate RSA Decryption key. I'm trying to write an RSA encryption program, and I'm stuck on calculating the decryption key. How do you check for coprimality?...
1
by: nithyapriya | last post by:
Hai, I'm nithya. I have a visual basic program that decrypts a file from my client using a passphrase. My seniors have no problem in the decryption. As I'm new to this concept, i could not...
0
by: Dipanwita | last post by:
I have written a RSA encryption/decryption function in c using the formula a = b^c %n. For solving the equation I have used Squaring and multiplying method for modulo exponentiation . These...
3
by: =?Utf-8?B?TG9yZW4=?= | last post by:
I’m trying to encrypt and decrypt a file in vb.net. I am using the TripleDESCryptoServiceProvider encryption found in System.Security.Cryptography. Below is the code for my Encrypt and Decrypt...
13
by: Tom Andrecht | last post by:
I'm trying to get some encryption/decryption routines going to take care of my data, and while the encryption is working great, I keep running into the message "Padding is invalid and cannot be...
9
by: Betikci Boris | last post by:
I get bored last night and wrote a script that uses xor for encrypt- decrypt, however it woks fine under linux 2.6.25, text and documents are ok, but fails on compressed files *.jpg, *.pdf , etc ....
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.