简体   繁体   中英

PKCS7 encryptor & decryptor in C#

I have been working on encryptor && decryptor in C#.I have two buttons for two different operations.I want to decrypt that encrypted file.But,I getting the following the error.

PKCS7 padding is invalid and cant be removed 

Code:

 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);}

 }

 }

There's limited support for PKCS#7 in .NET, and streaming is not supported.

See this question: Decrypting PKCS#7 encrypted data in C#

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM