Hellos, I have some problems with the function i2d_DSA_PUBKEY. I want serialize the public key to send this to a client Java for this can read this public key. I get serialize with openSSL, but the Java client throw an exception of the bad encoded when read this. Java have some functions to read PCS8 enconded key and x509 encoded key.
On the oder hand, I don't understand beccause I have allocate memory in the second parameter of the function i2d_DSA_PUBKEY if this is a pointer to pointer of the unsigned char threrefore the function can allocate memory in the pointer else why the parameter is a double pointer? Thank you very much. Here we have my source code. bool writeFile( char *fileName, unsigned char *data, unsigned int len ) { FILE *file = fopen( fileName, "wb" ); if( file == NULL ) return false; int writtenBytes = 0; int totalWrittenBytes = 0; while( totalWrittenBytes < len ) { writtenBytes = fwrite( &data[totalWrittenBytes], sizeof(unsigned char), len - totalWrittenBytes , file ); totalWrittenBytes += writtenBytes; } fclose( file ); return true; } int main( int argc, char **argv ) { DSA *dsa = DSA_new(); unsigned char ucDSAParams[1024]; // Seed the random number generator srand( time( NULL ) ); do { for( int it = 0; it < 1024; it ++ ) ucDSAParams[it] = rand() / RAND_MAX * 255; RAND_seed( ucDSAParams, 1024 ); }while( !RAND_status() ); while( !RAND_bytes( ucDSAParams, 1024 ) ); //Generate DSA parameters dsa = DSA_generate_parameters( 1024, ucDSAParams, 1024, NULL, NULL, NULL, NULL ); if( !DSA_generate_key( dsa ) ) { std::cout << "DSA_generate_key(..) error." << std::endl; return -1; } unsigned char *pubKeyInterchange = new unsigned char[1024]; int pubKeyInchgSize = 0; pubKeyInchgSize = i2d_DSA_PUBKEY( dsa, &pubKeyInterchange ); if( !writeFile( "pubkey.txt", pubKeyInterchange, pubKeyInchgSize ) ) { std::cout << "writeFile( .. ) error" << std::endl; return -8; } DSA_free( dsa ); return 1; } ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]