Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check pem file #40

Open
swuecho opened this issue Dec 12, 2023 · 0 comments
Open

check pem file #40

swuecho opened this issue Dec 12, 2023 · 0 comments

Comments

@swuecho
Copy link
Owner

swuecho commented Dec 12, 2023

Sure, I can provide you with a simple Python script to decode information in a PEM file. A PEM (Privacy Enhanced Mail) file can contain various types of encoded data, such as certificates or private keys. The following example assumes you have a PEM file with a certificate and demonstrates how to extract information from it using the cryptography library.

from cryptography import x509
from cryptography.hazmat.backends import default_backend

def decode_pem_file(pem_file_path):
    with open(pem_file_path, 'rb') as file:
        pem_data = file.read()

    # Decode the PEM data
    decoded_data = x509.load_pem_x509_certificate(pem_data, default_backend())

    # Extract information from the certificate
    subject = decoded_data.subject
    issuer = decoded_data.issuer
    not_before = decoded_data.not_valid_before
    not_after = decoded_data.not_valid_after
    serial_number = decoded_data.serial_number

    # Print the extracted information
    print(f"Subject: {subject}")
    print(f"Issuer: {issuer}")
    print(f"Not Before: {not_before}")
    print(f"Not After: {not_after}")
    print(f"Serial Number: {serial_number}")

# Replace 'your_certificate.pem' with the path to your PEM file
decode_pem_file('your_certificate.pem')

Make sure to replace 'your_certificate.pem' with the actual path to your PEM file. This script uses the cryptography library, so you may need to install it using:

pip install cryptography

Please note that the script assumes your PEM file contains an X.509 certificate. If your PEM file contains other types of data, such as private keys, you may need to adjust the script accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant