Note that there are some explanatory texts on larger screens.

plurals
  1. PODecryption using the public key
    primarykey
    data
    text
    <p>I want to encrypt some data with my private RSA key and then decrypt it on the client machine with the public key. As far as I know, this is a normal way of using RSA. However, as far as I see, there is a problem with this in <code>RSACryptoServiceProvider</code> of the .NET Framework. While the decryption works fine when you provide both the public and the private key to the <code>RSACryptoServiceProvider</code>, it doesn't when you only provide only the public key. In this case, I get a padding error:</p> <pre><code>Error occurred while decoding OAEP padding. at System.Security.Cryptography.RSACryptoServiceProvider.DecryptKey(SafeKeyHandle pKeyContext, Byte[] pbEncryptedKey, Int32 cbEncryptedKey, Boolean fOAEP, ObjectHandleOnStack ohRetDecryptedKey) at System.Security.Cryptography.RSACryptoServiceProvider.Decrypt(Byte[] rgb, Boolean fOAEP) </code></pre> <p>Notes :</p> <ul> <li>I encrypt/decrypt with <code>fOAEP</code> set to <code>true</code>.</li> <li>I use a 1024 key size and the data that I want to encrypt are no longer than 65 bytes.</li> <li>I load my keys from XML.</li> </ul> <p>Am I missing sth? I don't see any setting for the padding that I can change.</p> <p>Definitely, I can't send my private key to the client machine...</p> <p>Should I try another library like Bouncy Castle ?</p> <p>I have found <a href="https://stackoverflow.com/questions/7847743/using-an-rsa-public-key-to-decrypt-a-string-that-was-encrypted-using-rsa-private">this</a> question too, but there is no clear solution and, according to the author, his final solution was to use code from <a href="http://www.codeproject.com/Articles/38739/RSA-Private-Key-Encryption" rel="nofollow noreferrer">this article</a>. However, I would prefer to use the .NET Framework's code if possible and I don't understand why my decryption fails.</p> <p>Also, I don't think that my data is so long that <a href="https://stackoverflow.com/a/7849202/964053">this answer</a> is of any relevance.</p> <p>Perhaps I could use SignHash()/VerifyHash() but I think those calculate the hash from the data before encrypting it while I already have a hash computed and I just need to encrypt it. Using SignHash() will limit the variety of hashing algorithms that I could use, so it may be better to avoid it. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload