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. Algorithms
  4. AES Rijndael Cryptography fails

AES Rijndael Cryptography fails

Scheduled Pinned Locked Moved Algorithms
comalgorithmssecurityhelpquestion
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.
  • L Offline
    L Offline
    Leonardo Muzzi
    wrote on last edited by
    #1

    Hi. I'm currently using AES Rijndael cryptography throught my system. Actually, I was making some tests and found an error. The thing is, when I try to encrypt/decrypt some specific texts, I loose some data in the end of the resulting string. For instance: 15ª Instância 13º lugar ªªAB The above text, when encrypted/decrypted, results in loosing the two lasts chars "AB". I made some tests and figure out that any 4 characters after the "ªª" are lost. If you put 5 characters ("ABCDE"), then a new data block is created by the algorithm to seize the last letter and nothing is lost. Aparently it has something to do with the "ª" and "º" characters. If the last block of information (a block has 16 chars, 128 bits, in Rijndael) has any of these special chars, then the last chars of the block are lost in the roundtrip. If there is "ª" or "º" in a block that is not the last one, then everything runs fine. I'm using the code provided in MSDN site: http://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged.aspx[^] and padding the string block myself (using PaddingMode.None in Rijndael object). Does anyone knows why these special chars causes this error?

    L 1 Reply Last reply
    0
    • L Leonardo Muzzi

      Hi. I'm currently using AES Rijndael cryptography throught my system. Actually, I was making some tests and found an error. The thing is, when I try to encrypt/decrypt some specific texts, I loose some data in the end of the resulting string. For instance: 15ª Instância 13º lugar ªªAB The above text, when encrypted/decrypted, results in loosing the two lasts chars "AB". I made some tests and figure out that any 4 characters after the "ªª" are lost. If you put 5 characters ("ABCDE"), then a new data block is created by the algorithm to seize the last letter and nothing is lost. Aparently it has something to do with the "ª" and "º" characters. If the last block of information (a block has 16 chars, 128 bits, in Rijndael) has any of these special chars, then the last chars of the block are lost in the roundtrip. If there is "ª" or "º" in a block that is not the last one, then everything runs fine. I'm using the code provided in MSDN site: http://msdn.microsoft.com/en-us/library/system.security.cryptography.rijndaelmanaged.aspx[^] and padding the string block myself (using PaddingMode.None in Rijndael object). Does anyone knows why these special chars causes this error?

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

      Hi, my guess would be you are mixing up character counts and byte counts somehow. In UTF8 your special characters would take 2 bytes each. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


      L 1 Reply Last reply
      0
      • L Luc Pattyn

        Hi, my guess would be you are mixing up character counts and byte counts somehow. In UTF8 your special characters would take 2 bytes each. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        - before you ask a question here, search CodeProject, then Google - the quality and detail of your question reflects on the effectiveness of the help you are likely to get - use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


        L Offline
        L Offline
        Leonardo Muzzi
        wrote on last edited by
        #3

        Thanks for the advice, that was the problem. In fact, the real problem is that PaddingMode.PKCS7 doesn't work properly. Using this mode, in the roundtrip, I always get the error "PKCS7 padding is invalid and cannot be removed.". That's why I tried to do the padding myself, but it is not possible to do it in the string, because of the special characters that takes more than one byte. So, the solution was: I implemented the PKCS7 myself, in the byte array, right before the encryption, using PaddingMode.None for the RijndaelManaged. That worked fine. However, in the decryption, it was not necessary to implement it, the PaddingMode.PKCS7 worked correctly. Thanks to this article, "Notes On Padding" section: http://www.codeproject.com/KB/security/Cryptor.aspx[^]

        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