TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dozd
NA
65
0
Padding is invalid and cannot be removed
Mar 29 2009 6:57 AM
Hi I try to write simple code about encryption-decryption some text.
It encrypts well but after decryption it throws en exception "Padding is invalid and cannot be removed" during stream reader reads.That line is : "textBox1.text = sr.ReadToEnd();"
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream(@"C:\enkripcija.txt", FileMode.Open, FileAccess.ReadWrite);
RijndaelManaged rm = new RijndaelManaged();
CryptoStream cs = new CryptoStream(fs, rm.CreateEncryptor(rm.Key, rm.IV), CryptoStreamMode.Write);
StreamWriter sw = new StreamWriter(cs, Encoding.UTF8);
sw.Write("Something written for encryption");
sw.Close();
cs.Close();
fs.Close();
}
private void button2_Click(object sender, EventArgs e)
{
FileStream fs = new FileStream(@"C:\enkripcija.txt", FileMode.Open, FileAccess.Read);
RijndaelManaged rm = new RijndaelManaged();
CryptoStream cs = new CryptoStream(fs, rm.CreateDecryptor(rm.Key, rm.IV), CryptoStreamMode.Read);
StreamReader sr = new StreamReader(cs, Encoding.UTF8);
textBox1.text = sr.ReadToEnd();
sr.Close();
cs.Close();
fs.Close();
}
}
Reply
Answers (
0
)
Basic doubt By a Beginner Please Help?????????
Enum elements count