Padding is invalid and cannot be removed.
-
I have an error : Padding is invalid and cannot be removed. I want to decrypt a file but I receive that error. My code looks like this:
Sub DecryptTextFromFile(ByVal Key() As Byte, ByVal IV() As Byte) Dim var As String = My.Application.Info.DirectoryPath + "\text.txt" Try ' Create or open the specified file. Dim fStream As FileStream = File.Open(var, FileMode.OpenOrCreate) ' Create a new Rijndael object. Dim RijndaelAlg As Rijndael = Rijndael.Create ' Create a CryptoStream using the FileStream ' and the passed key and initialization vector (IV). Dim cStream As New CryptoStream(fStream, _ RijndaelAlg.CreateDecryptor(Key, IV), _ CryptoStreamMode.Read) RijndaelAlg.Padding = PaddingMode.PKCS7 ' Create a StreamReader using the CryptoStream. Dim sReader As StreamReader = New StreamReader(cStream) dim var23 as String=sReader.ReadLine() 'Read the data from the stream 'to decrypt it. Dim val As String = "" Try val = sReader.ReadLine() Catch e As Exception MessageBox.Show("An error occurred: {0}", e.Message) Finally ' Close the streams and ' close the file. sReader.Close() cStream.Close() fStream.Close() End Try Catch e As CryptographicException MessageBox.Show("A Cryptographic error occurred: {0}", e.Message) 'Return Nothing Catch e As UnauthorizedAccessException MessageBox.Show("A file error occurred: {0}", e.Message) 'Return Nothing End Try End Sub
Thanks. I search google but I didn't find something that can help me. -
I have an error : Padding is invalid and cannot be removed. I want to decrypt a file but I receive that error. My code looks like this:
Sub DecryptTextFromFile(ByVal Key() As Byte, ByVal IV() As Byte) Dim var As String = My.Application.Info.DirectoryPath + "\text.txt" Try ' Create or open the specified file. Dim fStream As FileStream = File.Open(var, FileMode.OpenOrCreate) ' Create a new Rijndael object. Dim RijndaelAlg As Rijndael = Rijndael.Create ' Create a CryptoStream using the FileStream ' and the passed key and initialization vector (IV). Dim cStream As New CryptoStream(fStream, _ RijndaelAlg.CreateDecryptor(Key, IV), _ CryptoStreamMode.Read) RijndaelAlg.Padding = PaddingMode.PKCS7 ' Create a StreamReader using the CryptoStream. Dim sReader As StreamReader = New StreamReader(cStream) dim var23 as String=sReader.ReadLine() 'Read the data from the stream 'to decrypt it. Dim val As String = "" Try val = sReader.ReadLine() Catch e As Exception MessageBox.Show("An error occurred: {0}", e.Message) Finally ' Close the streams and ' close the file. sReader.Close() cStream.Close() fStream.Close() End Try Catch e As CryptographicException MessageBox.Show("A Cryptographic error occurred: {0}", e.Message) 'Return Nothing Catch e As UnauthorizedAccessException MessageBox.Show("A file error occurred: {0}", e.Message) 'Return Nothing End Try End Sub
Thanks. I search google but I didn't find something that can help me.Hi,
WhiteGirl23 wrote:
I search google but I didn't find something that can help me
Very strange. I googled for "Padding is invalid and cannot be removed" and got 526 hits; I read a few, and trust the solution is there. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
-
Hi,
WhiteGirl23 wrote:
I search google but I didn't find something that can help me
Very strange. I googled for "Padding is invalid and cannot be removed" and got 526 hits; I read a few, and trust the solution is there. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
thanks for your time. I found the solution for my problem