Re: Another RSACryptoServiceProvider question

From: Pieter Philippaerts (Pieter_at_nospam.mentalis.org)
Date: 10/29/03

  • Next message: Daryn Kiely: "Re: Another RSACryptoServiceProvider question"
    Date: Wed, 29 Oct 2003 20:49:43 +0100
    
    

    "Daryn Kiely" <anonymous@discussions.microsoft.com> wrote in message
    > This works great if the fOAEP flag is
    > false (use PKCS padding) but fails if I use OAEP
    > padding. In both cases the encryption works, but in the
    > latter case the code throws a Cryptographic Exception
    > with the message "Error occured while decoding OAEP
    > padding".

    There are two problems with your code. The first is that you use the
    rsaEncrypt object to both encrypt and decrypt. rsaEncrypt.Decrypt will
    obviously not work because it doesn't have access to the private key.
    However I assume it was an error in your post and not an error in the code
    you're using because you said PKCS#1 worked.

    Secondly, you're trying to encrypt/decrypt too many bytes. If you change the
    number of bytes you're trying to encrypt to 86, everything works perfectly.
    This is in accordance with the MSDN documentation, that states "Modulus
    size -2 -2*hLen, where hLen is the size of the hash". If you take modulus
    size to be 128 bytes [or 1024 bits] and hLen 20 bytes [ie. SHA-1], you get
    128 - 2 - 2 * 20 = 86.
    It's strange that the encrypt method works and the decrypt doesn't. The
    encrypt method should have thrown an exception.

    Regards,
    Pieter Philippaerts
    Managed SSL/TLS: http://www.mentalis.org/go.php?sl


  • Next message: Daryn Kiely: "Re: Another RSACryptoServiceProvider question"

    Relevant Pages

    • Re: Another RSACryptoServiceProvider question
      ... > false (use PKCS padding) but fails if I use OAEP ... > with the message "Error occured while decoding OAEP ... number of bytes you're trying to encrypt to 86, ... It's strange that the encrypt method works and the decrypt doesn't. ...
      (microsoft.public.dotnet.security)
    • Re: Electronic Codebook/Cipher Block Chaining/Cipher Feedback/ Output Feedback
      ... Then you can snip out the padding after ... file types you encrypt are always in mutliples of 2 and at that you still ... know you gave is the correct keys so this is that data. ... compress this from one of Scott's bijective compressors or what? ...
      (sci.crypt)
    • Re: Padding twice in GCM - why?
      ... to a block boundary with zeros *twice*, first at the end of the ... "AAD", and then again at the end ... lot of padding at the end of the ciphertext. ... In the encrypt direction, a pipelined implementation of GCM (and GCM was ...
      (sci.crypt)
    • RE: AES 128 CryptEncrypt problem ,help me thanks
      ... The reason you see this is because by default block encryption is done with ... If you really want to (eg. you do your own padding and you communicate the ... recommended to use ECB mode. ... BLOCK size which AES_128 can encrypt by once is 16byte. ...
      (microsoft.public.platformsdk.security)
    • Re: How to encrypt a data small than 128 bits
      ... say from 4 bytes to 256 bytes; but AES uses to encrypt 128 ... Look up "block cypher modes"to see how to use a block cypher for text ... For padding there are two common methods. ... For CTR mode you do not need padding as a block cypher in CTR mode is ...
      (sci.crypt)