Do any PHP libraries exist for parsing ASN.1 or generating PHP code based on it?

Grekker picture Grekker · Jun 7, 2011 · Viewed 7.6k times · Source

I've already looked myself but it seems my Google-fu is not strong today.

I'm working to develop a standardized protocol for exchanging data structures over a TCP/IP connection between an Apache / PHP server and embedded C code on a microcontroller.

We are using ASN.1 notation, and what I would really like to do is to have a piece of PHP code that can parse the ASN.1 document and use it to interpret incoming data. It would produce a PHP object (or array) that is structured appropriately based on the ASN.1. The goal here would be for the PHP that parses the document and creates the objects to be agnostic of the document specifics (i.e. not hand-coded to match the document contents).

Alternatively, if this is not possible, does something exist that would let me generate simple PHP data transfer object classes that I could re-run each time the ASN.1 protocol document changed? This might actually be preferable from an efficiency perspective, as you wouldn't have to re-interpret the ASN.1 for each incoming request.

Thanks! Let me know if I can provide any additional clarification that would help to answer this question.

Answer

Friedrich Große picture Friedrich Große · Oct 3, 2012

Just in case somebody else is looking for an answer on this one: You may try PHPASN1 for a pure ASN.1 encoding and decoding library, or phpseclib which can also handle ASN.1, but it isn't as focused on it.

I am the developer of FGrosse/PHPASN1.