Re: Another RSACryptoServiceProvider question

From: Daryn Kiely (anonymous_at_discussions.microsoft.com)
Date: 10/30/03


Date: Wed, 29 Oct 2003 15:08:12 -0800

Thanks Pieter,

This resolved my problem, (I hate out by 1 errors), but I
still don't know why encryption worked.

Daryn

>-----Original Message-----
>"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
>



Relevant Pages

  • RE: NTE_BAD_DATA
    ... They are NOT used DIRECTLY to encrypt / decrypt data; ... you should generate a RANDOM SESSION KEY and select a SYMMETRIC ENCRYPTION ... // imported from a BLOB read in from the source file or having ...
    (microsoft.public.platformsdk.security)
  • Re: Back Doors
    ... >> Design into the system a master key. ... Encrypt that with public key. ... Decrypt random symmetric key with private key. ...
    (sci.crypt)
  • Re: CAPI and RC4: can not decrypt when Final parameter is set to F
    ... to store ASYMMETRIC key pairs - never symmetric keys like RC4, ... Now when you need to encrypt at one place and decrypt at the other normally ... Get a HCRYPTPROV handle to a key container with CryptAcquireContext ...
    (microsoft.public.platformsdk.security)
  • Re: RSA - Public vs. Private Keys
    ... This is a common pattern for license software ... your client will send a unique machine hash to the ... will let us decrypt with a Public Key (or simply not ... |> RSA is intended to encrypt messages with public keys only. ...
    (microsoft.public.dotnet.security)
  • Re: .NET Crypto Classes Interoperability with Win32 Crypto APIs
    ... when i encrypt a string using .NET classes and try to ... > decrypt it using Win32 APIs, ... > UnicodeEncoding(); ...
    (microsoft.public.dotnet.security)