title: How to Encode ASN.1 Context-specific using Openssl
body: <p>I am trying to encode the pkcs7 encapsulated content info:</p>
  
  <pre><code>Sequence:
    OID
    [0] Context-specific
       OCTET STRING
  </code></pre>
  
  <p>My first problem is to encode Context-specific:</p>
  
  <pre><code>[0] Context-specific
  </code></pre>
  
  <p>So I tried to create a 'SET Context-specific' with 'Octet String', but without success:</p>
  
  <pre><code>// Create ASN1_OCTET
  ASN1_OCTET_STRING *obj = ASN1_OCTET_STRING_new();
  const BYTE* ptr = dataToSign.getData();
  ASN1_OCTET_STRING_set(obj, ptr, dataToSign.getSize());
  
  // Create ASN1_TYPE using ASN1_OCTET
  ASN1_TYPE   *asn1Type   = ASN1_TYPE_new();
  asn1Type-&gt;type = V_ASN1_OCTET_STRING;
  asn1Type-&gt;value.octet_string = obj;
  
  // Using i2d_ASN1_SET_OF_ASN1_TYPE
  stack_st_ASN1_TYPE* sk = sk_ASN1_TYPE_new_null();
  sk_ASN1_TYPE_push(sk,asn1Type);
  int tamanho = i2d_ASN1_SET_OF_ASN1_TYPE(sk,(unsigned char **) NULL, i2d_ASN1_TYPE,V_ASN1_SET, V_ASN1_CONTEXT_SPECIFIC, IS_SET);
  unsigned char* data = new BYTE[tamanho];
  tamanho = i2d_ASN1_SET_OF_ASN1_TYPE(sk,(unsigned char **) &amp;data, i2d_ASN1_TYPE,V_ASN1_SET, V_ASN1_CONTEXT_SPECIFIC, IS_SET);
  </code></pre>
  
  <p>I have not found documentation on the website of <a href="http://www.openssl.org/docs/" rel="nofollow">openssl</a>.
  This place is better <a href="http://www.umich.edu/~x509/ssleay/" rel="nofollow">umich - Openssl documentation</a></p>
  
  <p>Am I on the right track?</p>