0

I need to sign xml using xmlSecDSigCtxSign. I need to create xmlSecDSigCtxPtr using xmlSecDSigCtxCreate method. I have PCCERT_CONTEXT found by CertFindCertificateInStore(). I'm calling xmlSecCryptoAppKeysMngrCertLoadMemory with success, signKey in xmlSecDSigCtx is NULL. I'm feeling that I'm doing something wrong.

HCERTSTORE hStore = NULL;
hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, 0, CERT_SYSTEM_STORE_CURRENT_USER, storeName.c_str());//storeName.c_str());
PCCERT_CONTEXT pContext = NULL;
pContext = CertFindCertificateInStore(hStore,
                                      X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0, CERT_FIND_HASH,
                                      &hashBlob, NULL);
xmlSecCryptoAppKeysMngrCertLoadMemory(mngr, pContext->pbCertEncoded, pContext->cbCertEncoded, xmlSecKeyDataFormatDer, xmlSecKeyDataTypeTrusted);
xmlSecDSigCtxPtr dsigCtx = xmlSecDSigCtxCreate(mngr);
xmlSecDSigCtxSign(dsigCtx, signNode);

May be I can init xmlsec specifying store? Please, help.

Nem
  • 336
  • 3
  • 8
  • 22
  • What's the error? – Michael Chourdakis Aug 12 '22 at 14:53
  • @M func=xmlSecKeysMngrGetKey:file=keys.c:line=1253:obj=unknown:subj=xmlSecKeysMngrFindKey:error=1:xmlsec library function failed: func=xmlSecDSigCtxProcessKeyInfoNode:file=xmldsig.c:line=793:obj=unknown:subj=unknown:error=45:key is not found:details=NULL func=xmlSecDSigCtxProcessSignatureNode:file=xmldsig.c:line=508:obj=unknown:subj=xmlSecDSigCtxProcessKeyInfoNode:error=1:xmlsec library function failed: func=xmlSecDSigCtxSign:file=xmldsig.c:line=291:obj=unknown:subj=xmlSecDSigCtxProcessSignatureNode:error=1:xmlsec library function failed: – Nem Aug 12 '22 at 14:56
  • The problem (i think) that dsigCtx->signKey is NULL. – Nem Aug 12 '22 at 14:57

0 Answers0