PeculiarVentures / graphene

A simple layer for interacting with PKCS #11 / PKCS11 / CryptoKI for Node in TypeScript. (Keywords: Javascript, PKCS#11, Crypto, Smart Card, HSM)
MIT License
169 stars 34 forks source link

Get publicKey from cert #155

Open lpinkas-ecosistemas opened 1 year ago

lpinkas-ecosistemas commented 1 year ago

Hello and first of all thank you for this amazing package! I need help signing and verifying with the provided cert and private key, which are already configured in the token (safenet 5110 etoken). I already managed to sign using the private key identifier, but I can't figure out how to get the public key from the certificate to verify the signature.

const privateKeys = session.find({
        class: graphene.ObjectClass.PRIVATE_KEY,
      });
      const privateKey = privateKeys.items(0);
      const sign = session.createSign('SHA256_RSA_PKCS', privateKey);
      sign.update('simple text 1');
      sign.update('simple text 2');
      const signature = sign.final();
      console.log('Signature RSA-SHA1:', signature.toString('hex')); // Signature RSA-SHA1: 6102a66dc0d97fadb5...

var verify = session.createVerify("SHA256_RSA_PKCS", ?????????);
      verify.update("simple text 1");
      verify.update("simple text 2");
      var verify_result = verify.final(signature);
      console.log("Signature RSA-SHA1 verify:", verify_result);      // Signature RSA-SHA1 verify: true

Any help would be greatly appreciated