0

We are building a Digitial Signing platform. Per user we generate a RSA 2048 key pair in an HSM, and issue a X509 digital certificate. During PAdEs or CAdES digital signing (Enveloping) we get the SHa256 hash 32 bytes that needs to be encrypted with user's RSA private key in order to complete signing operation.

What PKCS11 mechanism and function should we use to encrypt a hash with RSA private key?

It seems using CKM_SHA256_RSA_PKCS with C_Sign() will hash the hash and then sign/encrypt it. which is not what we want - unless i am mistaken.

Would this work: C_Encrypt(CKM_RSA_PKCS, privateKeyHandle, hashBytes)? according to documentation CKM_RSA_PKCS uses public key.

Many Thanks

user1912383
  • 359
  • 2
  • 6
  • 16
  • 1
    You are on the right way - "encrypted with ... private key" is the signing process. Maybe your HSM manufacturer provide some extensions to PKCS#11 library? – Alexander Jun 27 '22 at 11:46

1 Answers1

1

Yes. the method Sign is what you need.

In PKCS11Interop GitHub project page, there is an example named '_20_signAndVerifyTest.cs' in which uses a method with this signature:

byte[] Sign(IMechanism mechanism, IObjectHandler privateKeyHandle, byte[] sourceData)

The argument mechansim is made through:

Factories.MechansimFactory.Create(CKM.CKM_SHA1_RSA_PKCS)

which is a RSA mechansim. for setting its length, you should create a private key with 2048 modulus length.

is it what you need?

morteza
  • 125
  • 11