On Aug 17, 2010, at 12:37 PM, Leandro Santiago wrote: > It's really a basic doubt: How can I parse a file with the public key > to a struct which I can use to encrypt the string. Maybe just a > simple_example.c... :-) And also an example about decrypt using the > private key, of course :-) > > I'm reading this page: > http://www.openssl.org/docs/crypto/rsa.html > but manuals aren't good to a beginner :-)
Yes, it's pretty hard to get oriented when starting to use openssl. It's usually easier to avoid the lowest-level RSA_foo() functions in favor of the slightly more abstract EVP_(PKEY_)foo() functions. (This also lets you switch algorithms etc. later without rewriting everything.) IIRC, what you need to do is load the public or private key using either a PEM_read_* function or a d2i_*() function, depending on whether the key is in a PEM or DER format: http://www.openssl.org/docs/crypto/pem.html http://www.openssl.org/docs/crypto/d2i_PKCS8PrivateKey.html For the basic public-key operation, you use functions that operate on an EVP_PKEY_CTX: http://www.openssl.org/docs/crypto/EVP_PKEY_encrypt.html But for any real-world application, you'll want to do the standard business of generating a session key, encrypting the message using conventional symmetric encryption, and encrypting the session key with the public key. Since that's a lot of hassle and it's very easy to write something that works but isn't secure, it's probably a good idea to just adopt one of the higher level cryptographic containers such as CMS: http://www.openssl.org/docs/crypto/CMS_encrypt.html even though this does mean you start having to deal with all the X.509 crud. ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org