How to get values in char array or byte array from DER or PEM files?

  asn.1, c++, der, file, pem

I tried to develop some ECC features with PKCS#11 library in C++.
I generated some ECC key DER and PEM files by openssl.
For example, below is one of the DER files after decoded by ASN.1 JavaScript decoder.

EC_PRIVATEKEY ::= SEQUENCE {
  INTEGER 1
  OCTET STRING 61300E611C121ECBE7C2D49DA8FCD99571DF00296F51C3A9EC02DFF3063DBD3E
  [0]
    OBJECT IDENTIFIER 1.2.840.10045.3.1.7
  [1]
    BIT STRING 0004E924EC46F36A675528E2CA977A7D51C3E510993E092466F1A632419CC4A085F494F1B9D20E4B281484CB971B9AF99F088F11AB17A74928595075877D0047A4CC
}

How to get the "OCTET STRING" value in char array or byte array from the file?

The output may looks like :

//if the return is char array
privatekey = "61300E611C121ECBE7C2D49DA8FCD99571DF00296F51C3A9EC02DFF3063DBD3E";

or

//if the return is byte array
privatekey = {0x61,0x30,0x0E,0x61,0x1C,0x12,0x1E,0xCB,0xE7,0xC2,0xD4,0x9D,0xA8,0xFC,0xD9,0x95,0x71,0xDF,0x00,0x29,0x6F,0x51,0xC3,0xA9,0xEC,0x02,0xDF,0xF3,0x06,0x3D,0xBD,0x3E};

I have tried some functions from openssl such as PEM_read_ECPrivateKey, but I had not idea about the return data format and struct.

Source: Windows Questions C++

LEAVE A COMMENT