Hy. I am trying to encode a ASN1 structure with DER , but i get a parse error. My in text is : 304913214D617374657220646520736563757269746174656120696E666F726D6174696569301E170D3039313030313030303030305A170D3130303331353030303030305A020103010101

and the code is this:

include <openssl/asn1.h>
#include <stdio.h>
#include<conio.h>
#include <string.h>
#include <iostream>
#include <fstream>
#pragma comment( lib, "libeay32.lib" )
using namespace std;

int main()
{
	unsigned char buffer[150];
	BIO * outfile;
	FILE* intext = fopen("bla.txt", "rb" );
	outfile=BIO_new_file("out.txt","w+");
	if (intext!=NULL)
	{
		fread(buffer, 150, 1, intext);
		fclose(intext);
	
		ASN1_parse(outfile,buffer,150,0);
	}
	else
		printf("error");
	BIO_free(outfile);
	return 0;
}

Where does the error occur? If it is on this call ASN1_parse() then you're question definitely needs to go to the OpenSSL community.

Dave

the error is that it doesn't parse right. The output looks like this: 0:d=0 hl=2 l= 48 cons: PRINTABLESTRING Error in encoding

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.