PKCS7加密器& C#中的解密器

时间:2011-10-05 09:31:16

标签: c#

我一直致力于加密器&& C#中的解密器。我有两个按钮用于两个不同的操作。我想解密该加密文件。但是,我得到以下错误。

PKCS7 padding is invalid and cant be removed 

代码:

 private void button1_Click(object sender, System.EventArgs e)

 {try {

 if (DialogResult.OK==openFileDialog1.ShowDialog(this))

 {FileStream dosya=new FileStream("deneme.xxx",FileMode.Create);

  RijndaelManaged uygula=new RijndaelManaged();

 CryptoStream yenidosya=new CryptoStream(dosya,uygula.CreateEncryptor(),CryptoStreamMode.Write);

  FileStream tamam=new FileStream(openFileDialog1.FileName,FileMode.Open);

 int uzunluk;

 while((uzunluk=tamam.ReadByte())!=-1)

 {yenidosya.WriteByte((byte)uzunluk);}

 MessageBox.Show("islem tamam");

 tamam.Close();

 yenidosya.Close();

 dosya.Close();

 }

 }

 catch(Exception caught)

 {MessageBox.Show(caught.Message);}

 }

  private void button2_Click(object sender, System.EventArgs e)

 {

 try

 {

 if (DialogResult.OK==openFileDialog2.ShowDialog(this))

 {FileStream dosya=new FileStream(openFileDialog2.FileName,FileMode.Open);

 RijndaelManaged uygula=new RijndaelManaged();

 CryptoStream yenidosya=new CryptoStream(dosya,uygula.CreateDecryptor(),CryptoStreamMode.Read);

 FileStream tamam=new FileStream("denemeeeee.txt",FileMode.Create);

 int uzunluk;

 while((uzunluk=yenidosya.ReadByte())!=-1)

 {tamam.WriteByte((byte)uzunluk);}

 tamam.Close();

 yenidosya.Close();

 dosya.Close();

 MessageBox.Show("islem tamam");

  }

 }

 catch(Exception caught)

 {MessageBox.Show(caught.Message);}

 }

 }

1 个答案:

答案 0 :(得分:1)

.NET中对PKCS#7的支持有限,不支持流式传输。

请参阅此问题:Decrypting PKCS#7 encrypted data in C#