> From: [email protected] On Behalf Of cocostaec
> Sent: Thursday, 26 May, 2011 15:17

> can anyone tell a way how to parse a BER encoded string an 
> then decode it to
> ASN1?i've tried:
> [code]
> unsigned char* buffer;
> buffer=new unsigned char[strlen("0x3049<snipped>")];
> 
> strcpy((char*)buffer,"<same>");
> BIO * outfile;
> outfile=BIO_new_file("out.txt","w+");
> 
> ASN1_parse(outfile,buffer,150,0);//strlen("<same>"),0);

What you've got there is a hex *encoding* of BER, with a stray 0x 
on the front. Either use the C compiler to convert hex to bytes like:
  unsigned char buffer [/*autosized*/] = {0x30, 0x49, .... 0x01};
and then call ASN1_parse (outbio,buffer,sizeof buffer,indent);

or write code to decode the hex something like:
  unsigned char buffer [BIGENUF]; int buflen = 0;
  const char * hex = "3049...01"; // no 0x
  while( *hex ){
    int temp1, temp2; unsigned int tempu;
    temp2 = sscanf (hex, "%2x%n", &tempu, &temp1);
    if( temp2 != 1 || temp1 != 2 ){ ERROR should never happen! }
    else buffer[buflen++] = tempu;
    hex += temp1; // or just hex += 2;
  }
  ASN1_parse(outbio, buffer, buflen, indent);


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [email protected]
Automated List Manager                           [email protected]

Reply via email to