RSA_PRIVATE_ENCRYPT(3SSL)

πŸ’– RSA_PRIVATE_ENCRYPT πŸ’–

okay bestie so this is a page from the OpenSSL manual, and it's filed under 3SSL β€” and listen, the two functions here are RSA_private_encrypt and RSA_public_decrypt, which do low-level signature operations. low-level. like, down in the basement. we're gonna talk about them anyway bc you deserve to know, but also I'm gonna tell you the whole time that they're deprecated, so don't get attached 🫢


✨ NAME ✨

RSA_private_encrypt, RSA_public_decrypt β€” low-level signature operations πŸ’…


✨ SYNOPSIS ✨

#include <openssl/rsa.h>

The following functions have been deprecated since OpenSSL 3.0, and can be hidden entirely by defining OPENSSL_API_COMPAT with a suitable version value, see openssl_user_macros(7):

int RSA_private_encrypt(int flen, unsigned char *from,
                        unsigned char *to, RSA *rsa, int padding);

int RSA_public_decrypt(int flen, unsigned char *from,
                       unsigned char *to, RSA *rsa, int padding);

✨ DESCRIPTION ✨

🚨 the big disclaimer, read it first 🚨

Both of the functions described on this page are deprecated. 😭 I'm not being dramatic (okay I'm being a little dramatic, but it's true). Applications should instead use EVP_PKEY_sign_init_ex(3), EVP_PKEY_sign(3), EVP_PKEY_verify_recover_init(3), and EVP_PKEY_verify_recover(3). those are the icons. those are the main characters. go use those πŸ’–

These functions handle RSA signatures at a low-level. like, manual-transmission level. iykyk.


πŸ’« RSA_private_encrypt()

RSA_private_encrypt() signs the flen bytes at from (usually a message digest with an algorithm identifier) using the private key rsa and stores the signature in to. to must point to RSA_size(rsa) bytes of memory. no more, no less, she's specific like that ✨

padding denotes one of the following modes:

  • RSA_PKCS1_PADDING β€” PKCS #1 v1.5 padding. heads up: this function does not handle the algorithmIdentifier specified in PKCS #1. So when you're generating or verifying PKCS #1 signatures, RSA_sign(3) and RSA_verify(3) should be used instead. not me warning you in advance 🫢
  • RSA_NO_PADDING β€” Raw RSA signature. this mode should only be used to implement cryptographically sound padding modes in the application code. and listen: signing user data directly with RSA is insecure. that's not me being cute, that's just facts, fr fr. πŸ’€

πŸ’« RSA_public_decrypt()

RSA_public_decrypt() recovers the message digest from the flen bytes long signature at from using the signer's public key rsa. to must point to a memory section large enough to hold the message digest β€” and the digest is smaller than RSA_size(rsa) - 11. do the math, girlie, allocate accordingly 🌸

padding is the padding mode that was used to sign the data. it's giving "match your keys to your locks" energy πŸ”‘


✨ RETURN VALUES ✨

  • RSA_private_encrypt() returns the size of the signature (i.e., RSA_size(rsa)). slay, predictable πŸ’…
  • RSA_public_decrypt() returns the size of the recovered message digest.

On error, -1 is returned; the error codes can be obtained by ERR_get_error(3). so if you see a -1, go ask ERR_get_error(3) what went wrong, she'll tell you 🌈


✨ SEE ALSO ✨

ERR_get_error(3), RSA_sign(3), RSA_verify(3), EVP_PKEY_sign(3), EVP_PKEY_verify_recover(3)

(the first three are the old crew, the last two are the glow-up πŸ‘‘)


✨ HISTORY ✨

Both of these functions were deprecated in OpenSSL 3.0. that's it, that's the history, she was iconic and then she was deprecated πŸŽ€


Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


and that's the whole page, bestie!! this was OpenSSL version 4.0.3, dated 2026-09-29, filed under RSA_PRIVATE_ENCRYPT(3SSL). go forth, use the EVP functions, hydrate, and don't sign raw user data with RSA πŸ§šπŸ’–βœ¨

πŸ“¦ where this page comes from