是否存在用于解析 ASN.1 或基于它生成 PHP 代码的 PHP 库?
我已经审视过自己了,但今天我的 Google-fu 似乎并不强。
我正在努力开发一种标准化协议,用于通过 TCP/IP 连接在 Apache / PHP 服务器和微控制器上的嵌入式 C 代码之间交换数据结构。
我们使用 ASN.1 表示法,我真正想做的是拥有一段可以解析 ASN.1 文档并使用它来解释传入数据的 PHP 代码。它将生成一个基于 ASN.1 适当构造的 PHP 对象(或数组)。这里的目标是让 PHP 解析文档并创建与文档细节无关的对象(即不手工编码来匹配文档内容)。
或者,如果这是不可能的,是否存在某种东西可以让我生成简单的 PHP 数据传输对象类,每次 ASN.1 协议文档更改时我都可以重新运行这些对象类?从效率的角度来看,这实际上可能更可取,因为您不必为每个传入请求重新解释 ASN.1。
谢谢!如果我可以提供任何有助于回答这个问题的额外说明,请告诉我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以防万一其他人正在寻找这个问题的答案:您可以尝试使用 PHPASN1 获取纯 ASN .1 编码和解码库,或者 phpseclib 也可以处理 ASN.1,但它不那么专注于它。
我是 FGrosse/PHPASN1 的开发者。
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.
phpseclib 可以像 OpenSSL 的 asn1parse 一样解码 ASN.1 结构:
http://phpseclib.sourceforge。 net/x509/asn1parse.php
如果你查看源代码,它需要一个 $asn1->decodeBER 返回的数组,将其呈现为显示的字符串。但我认为它相同的事实证明了 phpseclib 的强大功能。
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.
试试这个: https://web.archive.org/web/20160305171509/http://phpkode.com/source/s/mistpark-server/library/asn1.php。
与其说它是一个库,不如说它是一个脚本,但您可以像使用脚本一样使用它。
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.