Re: Problem to cipher/decypher a struct with RSA
Angel Martinez Gonzalez wrote: Hello: I want to cypher/decypher an struct: struct PeticionSeudonimo { char *mensaje; int id_peticion; DES_cblock *clave_simetrica; }peticion_seudonimo; To do this, I first convert this struct to char *: char *ptrPeticionSeudonimo = (char *)peticion_seudonimo; Then I use this function to cipher: char *CifradoClavePublica(RSA *claveRSA, char *texto) { char *textocifrado; textocifrado =malloc(RSA_size(claveRSA)); RSA_public_encrypt(strlen(texto)+1, texto, textocifrado, claveRSA, I wouldn't use strlen(), sizeof() might be more appropriate Nils __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Re: Problem to cipher/decypher a struct with RSA
Hello: Thanks Nils for you help, but I obtain the problem. I have tried your advice: RSA_public_encrypt(sizeof(texto)+1, texto, textocifrado, claveRSA, RSA_PKCS1_PADDING); but the problem is the same. - Original Message - From: Nils Larsch [EMAIL PROTECTED] To: openssl-users@openssl.org Sent: Thursday, May 12, 2005 9:51 AM Subject: Re: Problem to cipher/decypher a struct with RSA Angel Martinez Gonzalez wrote: Hello: I want to cypher/decypher an struct: struct PeticionSeudonimo { char *mensaje; int id_peticion; DES_cblock *clave_simetrica; }peticion_seudonimo; To do this, I first convert this struct to char *: char *ptrPeticionSeudonimo = (char *)peticion_seudonimo; Then I use this function to cipher: char *CifradoClavePublica(RSA *claveRSA, char *texto) { char *textocifrado; textocifrado =malloc(RSA_size(claveRSA)); RSA_public_encrypt(strlen(texto)+1, texto, textocifrado, claveRSA, I wouldn't use strlen(), sizeof() might be more appropriate Nils __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED] __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Re: Problem to cipher/decypher a struct with RSA
I'm afraid sizeof(texto) returns the size of the pointer itself (4 in case of IA-32), not the data length. sizeof(struct PeticionSeudonimo) would be more effective. Also, you are using pointers in your struct (like char *mensaje), which means you are ciphering the pointer only, not the data it is pointing to. HTH, Gyorgy [EMAIL PROTECTED] 5/11/2005 10:07:28 Hello: Thanks Nils for you help, but I obtain the problem. I have tried your advice: RSA_public_encrypt(sizeof(texto)+1, texto, textocifrado, claveRSA, RSA_PKCS1_PADDING); but the problem is the same. - Original Message - From: Nils Larsch [EMAIL PROTECTED] To: openssl-users@openssl.org Sent: Thursday, May 12, 2005 9:51 AM Subject: Re: Problem to cipher/decypher a struct with RSA Angel Martinez Gonzalez wrote: Hello: I want to cypher/decypher an struct: struct PeticionSeudonimo { char *mensaje; int id_peticion; DES_cblock *clave_simetrica; }peticion_seudonimo; To do this, I first convert this struct to char *: char *ptrPeticionSeudonimo = (char *)peticion_seudonimo; Then I use this function to cipher: char *CifradoClavePublica(RSA *claveRSA, char *texto) { char *textocifrado; textocifrado =malloc(RSA_size(claveRSA)); RSA_public_encrypt(strlen(texto)+1, texto, textocifrado, claveRSA, I wouldn't use strlen(), sizeof() might be more appropriate Nils __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED] __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED] __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Problem to cipher/decypher a struct with RSA
Hello: I want to cypher/decypher an struct: struct PeticionSeudonimo { char *mensaje; int id_peticion; DES_cblock *clave_simetrica; }peticion_seudonimo; To do this, I first convert this struct to char *: char *ptrPeticionSeudonimo = (char *)peticion_seudonimo; Then I use this function to cipher: char *CifradoClavePublica(RSA *claveRSA, char *texto) { char *textocifrado; textocifrado =malloc(RSA_size(claveRSA)); RSA_public_encrypt(strlen(texto)+1, texto, textocifrado, claveRSA, RSA_PKCS1_PADDING); return (textocifrado); } and I call this function at this way: solicitudCifrada = CifradoClavePublica(clavePublicaRSA_TTP, ptrPeticionSeudonimo); Then, I decipher (solicitudCifrada) using this function: char *DescifradoClavePrivada(RSA *claveRSA, char *texto) { char *textoclaro; textoclaro = malloc(RSA_size(claveRSA)); RSA_private_decrypt(RSA_size(claveRSA), texto, textoclaro, claveRSA, RSA_PKCS1_PADDING); return (textoclaro); } and I call this function at this way: solicitudDescifrada = DescifradoClavePrivada(clavePrivadaRSA_TTP, solicitudCifrada); Finally, I convert solicitudDescifrada from char * to struct: peticion_seudonimo_descifrada = (struct PeticionSeudonimo *)solicitudDescifrada; But, when I want to show the fields of this struct peticion_seudonimo_descifrada, I only obtain the first field (char *mensaje), the others fileds are missing. I obtain an error at execution time. This fields are disappear. What is wrong?. Thanks for your help. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]