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

雨燕双飞 提交于 2019-12-08 15:45:06

问题


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.


回答1:


Try this one: https://web.archive.org/web/20160305171509/http://phpkode.com/source/s/mistpark-server/library/asn1.php.

It's not so much a library as a script, but you can use it like one.




回答2:


phpseclib can decode ASN.1 structures identically to how OpenSSL's asn1parse does it:

http://phpseclib.sourceforge.net/x509/asn1parse.php

If you look at the source code it takes an array that $asn1->decodeBER returned and renders that into the string that's displayed. But the fact that it's identical is testament to phpseclib's power I think.




回答3:


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.



来源:https://stackoverflow.com/questions/6272020/do-any-php-libraries-exist-for-parsing-asn-1-or-generating-php-code-based-on-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!