Skip to content

check pem file #40

@swuecho

Description

@swuecho

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions