Open haumenphai opened 3 months ago
Same issues:
import io
import pkcs11
from pkcs11 import Mechanism, Attribute
from pkcs11 import KeyType
from pypdf import PdfReader, PdfWriter
from pkcs11.types import PrivateKey
import base64
# Path to your PKCS#11 library
PKCS11_LIB = '/usr/lib/viettel-ca_v6.so'
# Load the PKCS#11 library
lib = pkcs11.lib(PKCS11_LIB)
# Open the first available slot
slot = lib.get_slots(token_present=True)[0]
token = slot.get_token()
with token.open(user_pin='12345678') as session:
certificates = session.get_objects({pkcs11.Attribute.CLASS: pkcs11.ObjectClass.CERTIFICATE})
certs = [c for c in certificates]
cert = certs[-1]
der_cert = cert[pkcs11.Attribute.VALUE]
private_key = [key for key in session.get_objects(KeyType.RSA) if isinstance(key, PrivateKey)][1]
signature = private_key.sign('v2', mechanism=Mechanism.RSA_PKCS)
Hello.
I got this error while developing a digital signing application. I downgraded to version
0.6.0
and the error was gone but the signing result was not as I expected.PIP:
My Code:
OS: Ubuntu 20.04, 16GB RAM