Spellcheck CMS docs.
[openssl.git] / doc / crypto / EVP_PKEY_encrypt.pod
index 6d91039f45bf7d2cd9a95d83b39e536ae9c1aa45..382762094e9ba9350d3c6ab26b1398a866299df2 100644 (file)
@@ -45,7 +45,37 @@ indicates the operation is not supported by the public key algorithm.
 
 Encrypt data using OAEP (for RSA keys):
 
-[to be added]
+ #include <openssl/evp.h>
+ #include <openssl/rsa.h>
+
+ EVP_PKEY_CTX *ctx;
+ unsigned char *out, *in;
+ size_t outlen, inlen; 
+ EVP_PKEY *key;
+ /* NB: assumes key in, inlen are already set up
+  * and that key is an RSA public key
+  */
+ ctx = EVP_PKEY_CTX_new(key);
+ if (!ctx)
+       /* Error occurred */
+ if (EVP_PKEY_encrypt_init(ctx) <= 0)
+       /* Error */
+ if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_OAEP_PADDING) <= 0)
+       /* Error */
+
+ /* Determine buffer length */
+ if (EVP_PKEY_encrypt(ctx, NULL, &outlen, in, inlen) <= 0)
+       /* Error */
+
+ out = OPENSSL_malloc(outlen);
+
+ if (!out)
+       /* malloc failure */
+ if (EVP_PKEY_encrypt(ctx, out, &outlen, in, inlen) <= 0)
+       /* Error */
+
+ /* Encrypted data is outlen bytes written to buffer out */
 
 =head1 SEE ALSO