NAME
RSApublicencrypt, RSAprivatedecrypt - RSA public key cryptography
SYNOPSIS
#include
int RSApublicencrypt(int flen, unsigned char *from, unsigned char *to, RSA *rsa, int padding); int RSAprivatedecrypt(int flen, unsigned char *from, unsigned char *to, RSA *rsa, int padding);DESCRIPTION
RSApublicencrypt() encrypts the fflleenn bytes at ffrroomm (usually a session key) using the public key rrssaa and stores the ciphertext in ttoo. ttoo must point to RSAsize(rrssaa) bytes of memory. ppaaddddiinngg denotes one of the following modes: RSAPKCS1PADDINGPKCS #1 v1.5 padding. This currently is the most widely used mode.
RSAPKCS1OAEPPADDINGEME-OAEP as defined in PKCS #1 v2.0 with SHA-1, MGF1 and an empty
encoding parameter. This mode is recommended for all new applications. RSASSLV23PADDINGPKCS #1 v1.5 padding with an SSL-specific modification that denotes
that the server is SSL3 capable. RSANOPADDING Raw RSA encryption. This mode should only be used to implement cryptographically sound padding modes in the application code. Encrypting user data directly with RSA is insecure.fflleenn must be less than RSAsize(rrssaa) - 11 for the PKCS #1 v1.5 based
padding modes, less than RSAsize(rrssaa) - 41 for RSAPKCS1OAEPPADDING
and exactly RSAsize(rrssaa) for RSANOPADDING. The random number generator must be seeded prior to calling RSApublicencrypt(). RSAprivatedecrypt() decrypts the fflleenn bytes at ffrroomm using the private key rrssaa and stores the plaintext in ttoo. ttoo must point to a memory section large enough to hold the decrypted data (which is smaller than RSAsize(rrssaa)). ppaaddddiinngg is the padding mode that was used to encrypt the data.RETURN VALUES
RSApublicencrypt() returns the size of the encrypted data (i.e., RSAsize(rrssaa)). RSAprivatedecrypt() returns the size of the recovered plaintext.On error, -1 is returned; the error codes can be obtained by
ERRgeterror(3). CCOONNFFOORRMMIINNGG TTOOSSL, PKCS #1 v2.0
SEE ALSO
ERRgeterror(3), rand(3), rsa(3), RSAsize(3) HISTORY The ppaaddddiinngg argument was added in SSLeay 0.8. RSANOPADDING is available since SSLeay 0.9.0, OAEP was added in OpenSSL 0.9.2b.0.9.7l 2004-03-23 RSApublicencrypt(3)