Python加载ERCA PEM公钥失败求助:行驶记录仪签名验证遇错
加载ERCA PEM公钥解密行驶记录仪签名失败求助
背景
正在开发行驶记录仪文件签名验证功能,根据文档要求,需先使用欧洲ERCA公钥解密章节证书,获取厂商公钥后再验证章节签名,但文档理解难度较高,目前卡在公钥加载环节。
公钥信息
我有一份PEM格式的ERCA公钥,内容如下:
------------ BEGIN ERCA PK --------------- /UVDIAD//wHpgHY6REqVJQqVh4LR1UrPwyPSXzlGuBbpL8+dMrQqJhPRo2O05DUyoCZoYynI lmPMwAH3J4IGtqtlrShxhIpoD2pX2P2h14LJtYEpA+pbZuKpvh2FvdD9rnakYIjXGmF2sfap hBkQBCTcVtCEaqPIQ5DTUXoPEZLe3/dAkkzbpwAAAAAAAQAB ------------ END ERCA PK ---------------
加载代码
使用以下Python代码加载公钥:
file = open(".\\dddfiles\\EC_PK\\EC_PK.pem", 'rb') b = file.read() file.close() rsa.PublicKey.load_pkcs1_openssl_der(b)
触发错误
运行代码后抛出如下错误:
File "C:\Users\Oscar\Documents\QanALL_CMD_Tools\src\ddd_parser.py", line 97, in <module> _7601_.validate() File "C:\Users\Oscar\Documents\QanALL_CMD_Tools\src\parser7601.py", line 89, in validate rsa.PublicKey.load_pkcs1_openssl_der(b) File "C:\Users\Oscar\AppData\Roaming\Python\Python311\site-packages\rsa\key.py", line 375, in load_pkcs1_openssl_der (keyinfo, _) = decoder.decode(keyfile, asn1Spec=OpenSSLPubKey()) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Oscar\AppData\Roaming\Python\Python311\site-packages\pyasn1\codec\ber\decoder.py", line 1618, in __call__ raise error.PyAsn1Error( pyasn1.error.PyAsn1Error: <TagSet object, tags 0:32:13> not in asn1Spec: <OpenSSLPubKey schema object, tagSet=<TagSet object, tags 0:32:16>, subtypeSpec=<ConstraintsIntersection object>, componentType=<NamedTypes object, types <NamedType object, type header=<PubKeyHeader schema object, tagSet=<TagSet object, tags 0:32:16>, subtypeSpec=<ConstraintsIntersection object>, componentType=<NamedTypes object, types <NamedType object, type oid=<ObjectIdentifier schema object, tagSet <TagSet object, tags 0:0:6>>>, <NamedType object, type parameters=<Null schema object, tagSet <TagSet object, tags 0:0:5>, subtypeSpec <ConstraintsIntersection object, consts <SingleValueConstraint object, consts b''>>, encoding iso-8859-1>>>, sizeSpec=<ConstraintsIntersection object>>>, <NamedType object, type key=<OctetString schema object, tagSet <TagSet object, tags 0:0:3>, encoding iso-8859-1>>>, sizeSpec=<ConstraintsIntersection object>>
已尝试方法
- 将公钥保存为BIN格式文件加载
- 将公钥保存为TXT格式文件加载
以上方法均无法解决问题,恳请提供可行的解决方案。
内容的提问来源于stack exchange,提问作者Oscar K
相关产品推荐
相关产品推荐

