21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

If you are using a predefined padding method, you don’t have to worry about performing<br />

any padding yourself. However, you do need to worry about message<br />

length. If you try to encrypt a message that is too long, RSA_public_encrypt( ) will<br />

return 0. Again, you should be expecting to encrypt messages of no more than 32<br />

bytes, so this should not be a problem.<br />

See Also<br />

• PKCS #1 page: http://www.rsasecurity.com/rsalabs/pkcs/pkcs-1/<br />

• Recipes 7.1, 7.2, 7.8, 10.1<br />

7.11 Performing Raw Decryption Using an RSA<br />

Private Key<br />

<strong>Problem</strong><br />

You have a session key encrypted with an RSA public key (probably using a standard<br />

padding algorithm), and you need to decrypt the value with the corresponding<br />

RSA private key.<br />

Solution<br />

Your cryptographic library should have a straightforward API-to-RSA decryption<br />

algorithm: you should be able to give it the public key, the data to decrypt, a buffer<br />

for the results, and a specification as to what kind of padding was used for encryption<br />

(EME-OAEP padding is recommended; see Recipe 7.10). The size of the input<br />

message will always be equal to the bit length of RSA you’re using. The API function<br />

should return the length of the result, and this length will usually be significantly<br />

smaller than the input.<br />

If, for some reason, you need to implement RSA on your own (which we strongly<br />

recommend against), refer to the Public Key Cryptography Standard (PKCS) #1,<br />

Version 2.1 (the latest version).<br />

Discussion<br />

While RSA is believed to be secure if used properly, it is very easy to<br />

use improperly. Be sure to read the Recipe on RSA encryption and the<br />

general-purpose considerations for public key encryption in Recipe 7.1<br />

and 7.2 in addition to this one.<br />

336 | Chapter 7: Public Key Cryptography<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!