LudovicRousseau / PyKCS11

PKCS#11 Wrapper for Python
GNU General Public License v2.0
96 stars 35 forks source link

PyKCS11.PyKCS11Error: CKR_GENERAL_ERROR #76

Closed hrharish111 closed 3 years ago

hrharish111 commented 4 years ago

Your system information

Please describe your issue in as much detail as possible:

Describe what you expected should happen.

I am running the sample code for encrypt and decrypt as is in api documentation https://pkcs11wrap.sourceforge.io/api/samples.html#encrypt-and-decrypt

Describe what did happen. Error CKR_GENERAL_ERROR Traceback (most recent call last): File "encrypt_decr.py", line 40, in dec = session.decrypt(privKey, enc) File "/usr/lib64/python2.7/site-packages/PyKCS11/init.py", line 1191, in decrypt raise PyKCS11Error(rv) PyKCS11.PyKCS11Error: CKR_GENERAL_ERROR (0x00000005)

Steps for reproducing this issue:

  1. installed softHSMv2 from https://github.com/opendnssec/SoftHSMv2
  2. installed python wrapper from https://github.com/LudovicRousseau/PyKCS11
  3. running sample code from api documentation from https://pkcs11wrap.sourceforge.io/api/samples.html#encrypt-and-decrypt
LudovicRousseau commented 4 years ago

I can't reproduce your problem.

$ export PYKCS11LIB=/usr/local/lib/softhsm/libsofthsm2.so
$ ./encrypt.py 
Traceback (most recent call last):
  File "./encrypt.py", line 37, in <module>
    pubKey = session.findObjects([(CKA_CLASS, CKO_PUBLIC_KEY)])[0]
IndexError: list index out of range

Of course I need to generate an RSA key pair first.

$ ./generate.py 
$ ./encrypt.py 

message: 48656c6c6f20776f726c640d0a

encrypted: 2ca566af75f6e583017797406aa865326f798da09ce19c05263cc105c8dcd6edb2949d68a9a590fd1cd630ba40640f4d99c7f94a2404a4d407637596ca751cd864effad91635f6d22041c641b1bfecd968bc1873aab3ffcf65494d31e1005dfcef77e591fec0a7f704b2c38f7b3ef2d613bd90fadb7628790474f7dcb881ee28

decrypted: Hello world
LudovicRousseau commented 3 years ago

If you still have the problem please add comments on how to reproduce it.