Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Padding is invalid and cannot be removed.

Padding is invalid and cannot be removed.

Scheduled Pinned Locked Moved Visual Basic
helpgraphics
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    WhiteGirl23
    wrote on last edited by
    #1

    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.

    L 1 Reply Last reply
    0
    • W WhiteGirl23

      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.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      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


      W 1 Reply Last reply
      0
      • L Luc Pattyn

        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


        W Offline
        W Offline
        WhiteGirl23
        wrote on last edited by
        #3

        thanks for your time. I found the solution for my problem

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups