在 python 中解码 windows 证书序列号
Decoding windows certificate serial number in python
我正在尝试解码 X.509 证书的序列号,我在 Python (http://timgolden.me.uk/pywin32-docs/PyCERT_CONTEXT.html)
中使用 win32crypt 打开
import win32crypt
import sys
# lpszStoreProvider
CERT_STORE_PROV_SYSTEM = 0x0000000A
# dwFlags
CERT_SYSTEM_STORE_LOCAL_MACHINE = 0x00020000
def main(*argv):
store = win32crypt.CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, None, CERT_SYSTEM_STORE_LOCAL_MACHINE, "MY")
for cert in store.CertEnumCertificatesInStore():
print("1 Cert: " + str(cert))
print("2 CertEnumCertificateContextProperties: " + str(cert.CertEnumCertificateContextProperties()))
print("3 cert.Subject: " + win32crypt.CertNameToStr(cert.Subject))
print("4 SerialNumber: " + str(cert.SerialNumber))
if __name__ == "__main__":
print("Python {0:s} {1:d}bit on {2:s}\n".format(" ".join(item.strip() for item in sys.version.split("\n")), 64 if sys.maxsize > 0x100000000 else 32, sys.platform))
main(*sys.argv[1:])
print("\nDone.")
在内存中的表示如下:
序列号 = b'\x07\x00\x00\x00\x00\x00\xc3o\x0c\xfbK\xf8\xdf\xbe\x07\x00\x00\x00*'
我就是想不通,使用了什么样的编码以及如何解码?!
编辑:(..将字节写入正确的序列号:2a00000007bedff84bfb0c6fc3000000000007)
答案:已解码= int.from_bytes(cert.SerialNumber,"little")
我正在尝试解码 X.509 证书的序列号,我在 Python (http://timgolden.me.uk/pywin32-docs/PyCERT_CONTEXT.html)
中使用 win32crypt 打开import win32crypt
import sys
# lpszStoreProvider
CERT_STORE_PROV_SYSTEM = 0x0000000A
# dwFlags
CERT_SYSTEM_STORE_LOCAL_MACHINE = 0x00020000
def main(*argv):
store = win32crypt.CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, None, CERT_SYSTEM_STORE_LOCAL_MACHINE, "MY")
for cert in store.CertEnumCertificatesInStore():
print("1 Cert: " + str(cert))
print("2 CertEnumCertificateContextProperties: " + str(cert.CertEnumCertificateContextProperties()))
print("3 cert.Subject: " + win32crypt.CertNameToStr(cert.Subject))
print("4 SerialNumber: " + str(cert.SerialNumber))
if __name__ == "__main__":
print("Python {0:s} {1:d}bit on {2:s}\n".format(" ".join(item.strip() for item in sys.version.split("\n")), 64 if sys.maxsize > 0x100000000 else 32, sys.platform))
main(*sys.argv[1:])
print("\nDone.")
在内存中的表示如下:
序列号 = b'\x07\x00\x00\x00\x00\x00\xc3o\x0c\xfbK\xf8\xdf\xbe\x07\x00\x00\x00*'
我就是想不通,使用了什么样的编码以及如何解码?!
编辑:(..将字节写入正确的序列号:2a00000007bedff84bfb0c6fc3000000000007)
答案:已解码= int.from_bytes(cert.SerialNumber,"little")