Loading certificate file and key from inputstream or bytearray instead of file name #158
Replies: 1 comment 1 reply
-
Sure, that's possible, you just have to do what All joking aside, precisely what you have to do depends on how you intend to store the certificates and keys in your database, mainly whether you're storing the raw (binary) DER representation or its PEM-armored textual form. If you're working from raw bytes, then e.g. a certificate can be loaded like this: from asn1crypto import x509
cert_der_bytes = fetch_from_database(...)
my_cert = x509.Certificate.load(cert_der_bytes) If it's PEM-encoded, then you'll want to use something like this:
Admittedly keys are a little more complicated, since they can be encoded in a variety of ways (depending on encryption settings and whatnot). If you're capable of retrieving a raw ...while I was typing this I planned to post a link to the convenience wrappers around Long story short, here's code that you can (more or less) trivially copy-paste and tweak to do what you want: pyHanko/pyhanko/sign/general.py Lines 393 to 482 in 768959d In the next release, I'll provide a version that accepts an arbitrary binary IO handle. |
Beta Was this translation helpful? Give feedback.
-
Is it possible to call
SimpleSigner.load()
with a bytearray or string that represents the contents of thekey_file
andcert_file
SimpleSigner load method
class method load(key_file, cert_file, ca_chain_files=None, key_passphrase=None, other_certs=None, signature_mechanism=None, prefer_pss=False)
I want to keep the keys in a database instead of stored onto disk.
Sample code to sign PDF document:
Beta Was this translation helpful? Give feedback.
All reactions