Re: Strange NTE_BAD_KEY returned from CryptDecrypt
From: greatx (x_at_greatx.net)
Date: 02/21/05
- Next message: Rhett Gong [MSFT]: "RE: SE_REGISTRY_WOW64_64KEY?"
- Previous message: Freddo: "Re: CryptExportKey returning strange error"
- Next in thread: Valery Pryamikov: "Re: Strange NTE_BAD_KEY returned from CryptDecrypt"
- Reply: Valery Pryamikov: "Re: Strange NTE_BAD_KEY returned from CryptDecrypt"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 20 Feb 2005 20:19:45 -0800
Could any one find the solution to this?
I am having the same problem.
Eugene Gershnik [SDK MVP] wrote:
> Hi,
>
> I have an x509 certificate, a piece of data and a signature for it
created
> with the certificate's private key (rsa over sha1). I have a problem
trying
> to validate the signature using CryptVerifySignature (which always
returns
> 'bad signature') so I decided to try to decrypt the signature to see
the
> hash. However CryptDecrypt always returns NTE_BAD_KEY. The
certificate is
> valid and the context returned by CertCreateCertificateContext is ok
since I
> validate it just before use. CryptImportPublicKeyInfoEx also has no
> problems. What am I doing wrong? The relevant part of the code is as
> follows. All the calls succeed except CryptDecrypt. I am on XP SP1.
>
> HCRYPTPROV hProv;
> PCCERT_CONTEXT pContext;
> HCRYPTKEY hCryptKey;
> PCERT_PUBLIC_KEY_INFO pPublicKey;
>
> bres = CryptAcquireContext(&hProv,
> 0,
> MS_ENHANCED_PROV,
> PROV_RSA_FULL,
> CRYPT_MACHINE_KEYSET |
> CRYPT_SILENT); /*I am doing it from a service*/
> if (!bres)
> goto cleanup;
>
> pContext = CertCreateCertificateContext(X509_ASN_ENCODING,
> (const BYTE *)pcertificate,
> cert_size);
> if (!pContext)
> goto cleanup;
>
> pPublicKey = &(pContext->pCertInfo->SubjectPublicKeyInfo);
>
> bres = CryptImportPublicKeyInfoEx(hProv,
> X509_ASN_ENCODING,
> pPublicKey,
> CALG_RSA_SIGN, /*I tried KEYX too and it didn't help */
> 0,
> 0,
> &hCryptKey);
> if (!bres)
> goto cleanup;
>
> bres = CryptDecrypt(hCryptKey,
> 0,
> TRUE,
> 0,
> (BYTE *)psignature,
> &signature_size);
>
>
> Thanks,
> Eugene
- Next message: Rhett Gong [MSFT]: "RE: SE_REGISTRY_WOW64_64KEY?"
- Previous message: Freddo: "Re: CryptExportKey returning strange error"
- Next in thread: Valery Pryamikov: "Re: Strange NTE_BAD_KEY returned from CryptDecrypt"
- Reply: Valery Pryamikov: "Re: Strange NTE_BAD_KEY returned from CryptDecrypt"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|