Skip to content

Instantly share code, notes, and snippets.

View sakurai-youhei's full-sized avatar

Youhei Sakurai sakurai-youhei

  • Kobe, Japan
View GitHub Profile
@sakurai-youhei
sakurai-youhei / export_pkey.py
Created June 12, 2017 04:40
Export private key from *.pfx file (PKCS12) into PEM format using pyOpenSSL
from OpenSSL import crypto
with open("path/to/cert.pfx", "rb") as pfx:
cert = crypto.load_pkcs12(pfx.read())
pkey = cert.get_privatekey()
with open("path/to/pkey.pem", "wb") as pem:
pem.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey))
@sakurai-youhei
sakurai-youhei / pip_prog.py
Last active April 27, 2017 09:56
Run pip programmatically
from contextlib import contextmanager
from contextlib import redirect_stdout as r_stdout
from contextlib import redirect_stderr as r_stderr
from io import StringIO
import pip
def pip_exec(*args):
with StringIO() as stdout, StringIO() as stderr: