Advertisement
AntonioVillanueva

Certificat pfx dans Python Linux sans tmp

Nov 28th, 2023
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. #Version sans fichier temporel , retourne les chaines PEM
  2. """
  3. Retourne les chaines PEM directement
  4. """
  5.  
  6. # Chemin d'accès au fichier de certificat PFX et au mot de passe
  7. pfx_file_path = 'certificat.pfx'
  8. pfx_password = 'ClePublique'
  9.  
  10. from cryptography.hazmat.primitives import serialization
  11. from requests import Session
  12. import cryptography.hazmat.primitives.serialization.pkcs12
  13.  
  14.  
  15. with open(pfx_file_path, "rb") as f:
  16.     (
  17.         private_key,
  18.         certificate,
  19.         additional_certificates,
  20.     ) = serialization.pkcs12.load_key_and_certificates(
  21.         f.read(), pfx_password.encode()
  22.     )
  23.  
  24.  
  25. key_pem= private_key.private_bytes(
  26.     encoding=serialization.Encoding.PEM,
  27.     format=serialization.PrivateFormat.PKCS8,
  28.     encryption_algorithm=serialization.NoEncryption(),
  29. )
  30.  
  31. cert_pem= certificate.public_bytes(serialization.Encoding.PEM)
  32.  
  33.  
  34. print ("\nCert PEM : ",cert_pem)
  35. print ("\nKey Prive : ", key_pem)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement