Antonio Ruiz Martínez wrote:
>
> Hello!
>
> I'm a problem with ASN.1. Can anybody help me?
RTFM
> I've got a code that it creates an integer encoded in DER but I
> can't decode well the object.
> Where's the problem?
> My code is:
> ASN1_INTEGER *version=NULL;
> unsigned char *der=NULL;
>
> version=ASN1_INTEGER_new();
>
> ASN1_INTEGER_set(version,1243);
>
> long pp=ASN1_INTEGER_get(version);
> printf("Integer: %d\n",pp);
>
> int londer=i2d_ASN1_INTEGER(version,NULL);
> der=(unsigned char *)OPENSSL_malloc(londer);
unsigned char *der_tmp = der;
> londer= i2d_ASN1_INTEGER(version,&der);
must be:
londer = i2d_ASN1_INTEGER(version,&der_tmp);
der_tmp will point after the DER data !
(RTFM)
> ASN1_INTEGER *version2=NULL;
>
der_tmp = der;
> version2=d2i_ASN1_INTEGER(NULL,&der,londer);
version2=d2i_ASN1_INTEGER(NULL,&der_tmp,londer);
> pp=ASN1_INTEGER_get(version2);
> printf("Integer: %d\n",pp);
> This last printf says that the Integer is 0 but the integer is
> 1234.
> Why?
You ever tested the value of version2 ?
schould be a null pointer...
By
Goetz
--
Goetz Babin-Ebell, TC TrustCenter GmbH, http://www.trustcenter.de
Sonninstr. 24-28, 20097 Hamburg, Germany
Tel.: +49-(0)40 80 80 26 -0, Fax: +49-(0)40 80 80 26 -126
S/MIME Cryptographic Signature