Pyopenssl-which of the following PHP code about openSSL is implemented in Python?

Source: Internet
Author: User
Tags pkcs12
{Code ...} I wrote a Python version using pyopenssl, as follows: {code ...} the problem mainly lies in x509data. How can I get the data in x509data? In Python, this is an object.
function getCertId($cert_path) {    $pkcs12certdata = file_get_contents ( $cert_path );    openssl_pkcs12_read ( $pkcs12certdata, $certs, SDK_SIGN_CERT_PWD );    $x509data = $certs ['cert'];    openssl_x509_read ( $x509data );    $certdata = openssl_x509_parse ( $x509data );    $cert_id = $certdata ['serialNumber'];    return $cert_id;}

I wrote a Python version using pyopenssl, as shown below:

''' The certificate ID in pfx format is parsed. Here the signature certificate ''' def getCertIdWithPFX (cert_path): fp = open (cert_path, 'R') if not fp: raise Exception ('Open % s fail !!! '% Cert_path) pkcs12certdata = fp. read () ''' first parses the pkcs12 format ''' sdk_sign_cert_password = config ['sdk _ sign_cert_password '] certs = OpenSSL. crypto. load_pkcs12 (pkcs12certdata, sdk_sign_cert_password) ''' and parse the x509 format ''' x509data = certs. get_certificate () print x509data cert_data = OpenSSL. crypto. load_certificate (OpenSSL. crypto. FILETYPE_ASN1, x509data) print '-----------------', cert_data return cert_data.get_serial_number ()

The problem mainly lies in x509data. How can I get the data in x509data? In Python, this is an object.

Reply content:
function getCertId($cert_path) {    $pkcs12certdata = file_get_contents ( $cert_path );    openssl_pkcs12_read ( $pkcs12certdata, $certs, SDK_SIGN_CERT_PWD );    $x509data = $certs ['cert'];    openssl_x509_read ( $x509data );    $certdata = openssl_x509_parse ( $x509data );    $cert_id = $certdata ['serialNumber'];    return $cert_id;}

I wrote a Python version using pyopenssl, as shown below:

''' The certificate ID in pfx format is parsed. Here the signature certificate ''' def getCertIdWithPFX (cert_path): fp = open (cert_path, 'R') if not fp: raise Exception ('Open % s fail !!! '% Cert_path) pkcs12certdata = fp. read () ''' first parses the pkcs12 format ''' sdk_sign_cert_password = config ['sdk _ sign_cert_password '] certs = OpenSSL. crypto. load_pkcs12 (pkcs12certdata, sdk_sign_cert_password) ''' and parse the x509 format ''' x509data = certs. get_certificate () print x509data cert_data = OpenSSL. crypto. load_certificate (OpenSSL. crypto. FILETYPE_ASN1, x509data) print '-----------------', cert_data return cert_data.get_serial_number ()

The problem mainly lies in x509data. How can I get the data in x509data? In Python, this is an object.

From OpenSSL. crypto import load_pkcs12, FILETYPE_PEM, PKCS12, dump_certificate, dump_privatekey

Cert_pem = dump_certificate (FILETYPE_PEM, certs. get_certificate ())
Key_pem = dump_privatekey (FILETYPE_PEM, certs. get_privatekey ())

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.