有没有解析pkcs7的python包?
Is there any python package for parsing pkcs7?
我正在使用 androguard and right now I need to extract the serial number(*) from its signature file (usually CERT.RSA). I've found asn1crypto 从 Android.APK 文件中提取功能,但我不太明白如何将其与 pkcs7 一起使用。那么有没有适合这个目的的 python 包呢?
(*):
Comment: I have pkcs7 as a memory object, not a file
PyOpenSSL
没有从 文件中读取 !
OpenSSL.crypto.load_pkcs7_data(type, buffer)
Load pkcs7 data from the string buffer encoded with the type type.
The type type must either FILETYPE_PEM or FILETYPE_ASN1).
from
import get_certificates
from OpenSSL import crypto
pkcs7 = crypto.load_pkcs7_data(crypto.FILETYPE_ASN1,
open('certs/signature.der', 'rb').read())
certs = get_certificates(pkcs7)
for cert in certs:
print('Subject:{}, Serial Nnumber:{}'.
format(cert.get_subject(), cert.get_serial_number()))
>>>Subject:<X509Name object '/CN=key1'>, Serial Nnumber:13315126025841024674
>>>Subject:<X509Name object '/CN=key2'>, Serial Nnumber:14142490995367396705
Question: python package for parsing pkcs7?
您可以使用 openssl 将 PKCS#7 转换为 PEM,使用 PyOpenSSL
可读取 PEM
openssl pkcs7 -print_certs -in sample.p7b -out sample.cer
阅读相关的 SO 答案:
我正在使用 androguard and right now I need to extract the serial number(*) from its signature file (usually CERT.RSA). I've found asn1crypto 从 Android.APK 文件中提取功能,但我不太明白如何将其与 pkcs7 一起使用。那么有没有适合这个目的的 python 包呢?
(*):
Comment: I have pkcs7 as a memory object, not a file
PyOpenSSL
没有从 文件中读取 !
OpenSSL.crypto.load_pkcs7_data(type, buffer)
Load pkcs7 data from the string buffer encoded with the type type.
The type type must either FILETYPE_PEM or FILETYPE_ASN1).
from
import get_certificates
from OpenSSL import crypto
pkcs7 = crypto.load_pkcs7_data(crypto.FILETYPE_ASN1,
open('certs/signature.der', 'rb').read())
certs = get_certificates(pkcs7)
for cert in certs:
print('Subject:{}, Serial Nnumber:{}'.
format(cert.get_subject(), cert.get_serial_number()))
>>>Subject:<X509Name object '/CN=key1'>, Serial Nnumber:13315126025841024674
>>>Subject:<X509Name object '/CN=key2'>, Serial Nnumber:14142490995367396705
Question: python package for parsing pkcs7?
您可以使用 openssl 将 PKCS#7 转换为 PEM,使用 PyOpenSSL
可读取 PEMopenssl pkcs7 -print_certs -in sample.p7b -out sample.cer
阅读相关的 SO 答案: