What are you trying to do?
(give some details if you want any help)

Using RSA directly on the message is almost never a good idea.
(Correct me if I'm wrong but that's what you seem to be doing)
You should be using an intermediate symmetric cipher or just let openssl
or gnupg do its job and forget about the internal specifics of key
selection and protocol.

Eduardo

On 2005-05-16 07:21:25 UTC, Angel Martinez Gonzalez wrote:
> I want to cypher/decrypt messages with RSA.
> 
> I use this functions to cypher and decypher:
> 
> int CifradoClavePublica(RSA *claveRSA, char *texto, char **textocifrado)
> {
>  int size = RSA_size(claveRSA);
>  int blksize = size - 12;
>  int length = strlen(texto);
>  int blocks = length/blksize;
>  int rest = length%blksize;
> 
>  int i;
>  int tamano_datos_cifrados;
>  int longitud_datos_cifrados = 0;
> 
>  if (rest == 0)
>   *textocifrado = malloc(blocks*size+1);
>  else
>   *textocifrado = malloc((blocks+1)*size+1);
> 
> 
>  for (i=0; i<blocks; i++)
>  {
>   tamano_datos_cifrados = RSA_public_encrypt(blksize, texto+i*blksize,
> *textocifrado+i*size, claveRSA, RSA_PKCS1_PADDING);
>   longitud_datos_cifrados = longitud_datos_cifrados + tamano_datos_cifrados;
>   }
> 
>  if (rest != 0)
>  {
>   tamano_datos_cifrados = RSA_public_encrypt(rest, texto+blocks*blksize,
> *textocifrado+blocks*size, claveRSA, RSA_PKCS1_PADDING);
>   longitud_datos_cifrados = longitud_datos_cifrados + tamano_datos_cifrados;
>    }
> 
>  return (longitud_datos_cifrados);
> 
> }
> 
> This function returns the size of the encrypted data. "claveRSA" is the
> public key RSA,  "texto" is the message to cypher, and "textocifrado" stores
> the ciphertext.
> 
> 
> To decypher, I use this function:
> 
> char *DescifradoClavePrivada(RSA *claveRSA, char *texto, int
> longitud_datos_cifrados)
> {
>  int size = RSA_size(claveRSA);
>  int blksize = size-12;
>  int length = longitud_datos_cifrados;
>  int blocks = length/size;
> 
>  int i, error;
>  int written = 0;
>  char *textoclaro;
>  int tamano_datos_descifrados;
> 
>  char *fileError = "error.txt";
> 
>  FILE *fp;
> 
>   textoclaro = malloc(blocks*blksize+1);
> 
>  for (i=0; i<blocks; i++)
>  {
>   printf ("bucle %i\n",i);
>   tamano_datos_descifrados = RSA_private_decrypt(blksize, texto+i*size,
> textoclaro+written, claveRSA, RSA_PKCS1_PADDING);
> 
> 
>   ERR_load_crypto_strings();
>   error = ERR_get_error();
>   printf ("Library: %s\n", ERR_lib_error_string(error));
>   printf ("Function: %s\n", ERR_func_error_string(error));
>   printf ("Reason: %s\n", ERR_reason_error_string(error));
> 
>   written = written + tamano_datos_descifrados;
>  }
>  return (textoclaro);
> 
> }
> 
> This function returns the plain text. "claveRSA" is the private key RSA,
> "texto" is the cyphertext to decrypt, and "longitud_datos_cifrados" is the
> size of the encrypted data "texto".
> 
> And when I run this function, I obtain this error message:
> 
> Library: rsa routines
> Function: RSA_padding_check_PKCS1_type_2
> Reason: block type is not 02
> 
> What meaning this error?, What it is wrong?. Thanks.
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [email protected]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to