Hi,
I'm trying to write a pkcs7 object with following code to a file: unsigned char *tmp, signature; int iLen; iLen = i2d_PKCS7(p7, NULL); signature = (unsigned char*) malloc(iLen); tmp = signature; iLen = i2d_PKCS7(p7, &tmp); FILE *fpkcs7 = fopen("C:\\sig.p7s", "w+"); for(int i = 0; i < iLen; i++) fprintf(fpkcs7, "%c", signature[i]); fclose(fpkcs7); If I try to verify the file "sig.p7s" with an asn1 dump it isn't a valid asn1 structure. If I use the following code and dump "sig.p7s" there is no problem: FILE *fpkcs7 = fopen("C:\\sig.p7s", "w+"); BIO *out = BIO_new(BIO_s_file()); BIO_set_fp(out, fpkcs7, BIO_NOCLOSE); i2d_PKCS7_bio(out, p7); fclose(fpkcs7); Can anybody tell me what is the difference? The asn1 dump is 100% working correct! I have to use the DER representation of the pkcs7 object "p7" and so I want to use the first code but I don't know if it's working correct because I can't dump it! Best regards, Christian Wiesbauer