pyauth / python-pkcs11

PKCS#11/Cryptoki support for Python
MIT License
149 stars 71 forks source link

Question regarding get_keys() #157

Open bentterp opened 1 year ago

bentterp commented 1 year ago

I would appreciate a little guidance on the smart/correct way to get an object pointing to a previously generated key. The documentation shows how to generate or import a key and how to perform operations with keys, but not how to point to already existing keys. (I won't use the term "load" here or such as I do want the keys to remain inside the HSM when the crypto operation is done)

For a symmetric key, the label seems sufficient for specifying which key we want to use: symmetricKey = session.get_key(label='symmetric') but the generate_keypair() used for asymmetric key types leads to both public and private key having the same label so the best I have come up with so far is: privateAsymmetricKey = session.get_key(label='asymmetric', object_class=pkcs11.ObjectClass.PRIVATE_KEY) publicAsymmetricKey = session.get_key(label='asymmetric', object_class=pkcs11.ObjectClass.PUBLIC_KEY)

Apologies in advance if this is already documented somewhere I've failed to look (or read and failed to understand)