RSA 公钥文件类型检测
我得到了一个 RSA pubkey.dat(几乎很明显它是什么),其内容结构如下:
- ASN1 约 1024 位的整数(模数)
- ASN1 整数(指数)
- 256 字节的 Blob(签名)
没有像“---”这样的标签-开始---”左右。 其中纯十六进制值。
有什么方法可以识别它的格式,例如 DER/PEM/etc ,这样我就可以使用 python 加密库或 c++ 上的 crypto++ 打开它?
(或者如果它与公共标准结构名称匹配供我检查)
似乎它不是 PEM,因为 M2crypt 无法加载它。
提前致谢。
I got a RSA pubkey.dat (almost obvious what it is) that has the following structure on contents:
- ASN1 Integer of around 1024 bits (Modulus)
- ASN1 Integer (Exponent)
- Blob of 256 bytes (Signature)
No tags like "----begin---" or so. pure hex values in it.
There's any way to identify its format like if it's DER/PEM/etc , so i can open it with python crypto libraries or crypto++ on c++?
(Or if it matches a public standard structure name for me to check)
Seems like its not PEM as M2crypt can't load it.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PEM 编码具有强制格式:
其中,对于公钥,typeName="PUBLIC KEY" (AFAIR),因此很容易使用正则表达式进行检查,如下所示:
如果不是 PEM,则通常是纯 DER。
ASN.1 SEQUENCE 的 DER 表示始终以 0x30 开头,因此通常当我必须解码 DER-or-PEM 流时,我确信它是 ASN.1 SEQUENCE(无论如何,最复杂的值都是 SEQUENCE)我会检查第一个字节:如果它是 0x30,我解码为 DER,否则我解码为 PEM。
您可以使用我自己的开源ASN.1解析器快速检查您的ASN.1数据(这都是客户端- side Javascript,所以我不会看到你的数据)。
PEM-encoding has mandatory format:
where, for public keys, typeName="PUBLIC KEY" (AFAIR) so that's very easy to check with a regular expression such as the following:
If it's not PEM, it's usually plain DER.
The DER representation of an ASN.1 SEQUENCE always begins with 0x30 so usually when I have to decode a DER-or-PEM stream which I know for sure it's an ASN.1 SEQUENCE (most complex values are SEQUENCEs, anyways) I check the first byte: if its's 0x30, I decode as DER, else I decode as PEM.
You can check your ASN.1 data quickly using my very own opensource ASN.1 parser (it's all client-side Javascript, so I won't see your data).