Re: retrieving certificate's public key
From: AAA (aminrozie_at_yahoo.com)
Date: 09/09/03
- Next message: Merlin Ran: "open device drivers in non-administrator priviledge"
- Previous message: Robert Hoghaug: "Re: Q322047 Does not seem to Work for Enable Themes for non Admin"
- In reply to: Sergio Dutra [MS]: "Re: retrieving certificate's public key"
- Next in thread: Sergio Dutra [MS]: "Re: retrieving certificate's public key"
- Reply: Sergio Dutra [MS]: "Re: retrieving certificate's public key"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Tue, 9 Sep 2003 08:49:05 +0800
I'm having something similar too. I have an enterprise CA using MS Cert
Server setup. Do all the users receiving the certificates from this server
have the same public key? If so, how do I retrieve the public key from the
certificate and use that key to encrypt files? Also, how do I publish the
public key of each one of the users?
AAA
"Sergio Dutra [MS]" <sergiod@online.microsoft.com> wrote in message
news:O4i2G3WcDHA.1532@TK2MSFTNGP10.phx.gbl...
> The certificate's public key is in the certificate itself:
> PCCERT_CONTEXT->pCertInfo->SubjectPublicKeyInfo.
> If you actually want to get the private key, then you need to call
> CryptAcquireCertificatePrivateKey, which will work if the certificate
> already has the required KEY_PROV_INFO property.
>
> --
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> Use of included script samples are subject to the terms specified at
> http://www.microsoft.com/info/cpyright.htm
> "Bertrand" <balberola@amadeus.net> wrote in message
> news:0f2d01c36bf1$3edf2e50$a501280a@phx.gbl...
> > how should I use the crypto API to retrieve the public key
> > of a local machine certificate? I always get a NTE_BAD_KEY
> > error with the code below
> > Can somebody help? I'm going crazy...
> >
> >
> > bool ServerCertificate_Manager::getCertPublicKey(long
> > *lerrorcode, PCCERT_CONTEXT pcertcontxt, HCRYPTKEY *hkey,
> > bool islocal)
> > {
> > HCRYPTPROV hProvider = 0;
> > CRYPT_KEY_PROV_INFO *KeyProvInfo;
> > DWORD cbLen;
> > char *ContainerName;
> > char *ProvName;
> >
> > // Retrieve Provider Context associated with the
> > Certificate key container.
> > //the first call retrieves the size to allocate to
> > KeyProvInfo
> > //after allocating that size, the second call sets
> > the value
> > if (!CertGetCertificateContextProperty(
> >
> > pcertcontxt,
> >
> > CERT_KEY_PROV_INFO_PROP_ID,
> > NULL,
> > &cbLen))
> > {
> > *lerrorcode = ERROR_SCM_GETCERT_CONTXTPROP;
> > return false;
> > }
> >
> > KeyProvInfo = (CRYPT_KEY_PROV_INFO *)malloc(cbLen);
> > if (KeyProvInfo == NULL)
> > {
> > *lerrorcode = ERROR_SCM_BUFFER_REALLOC;
> > return false;
> > }
> >
> > if (!CertGetCertificateContextProperty(
> >
> > pcertcontxt,
> >
> > CERT_KEY_PROV_INFO_PROP_ID,
> >
> > KeyProvInfo,
> > &cbLen))
> > {
> > *lerrorcode = ERROR_SCM_GETCERT_CONTXTPROP;
> > free(KeyProvInfo);
> > return false;
> > }
> >
> > cbLen = wcstombs(NULL, KeyProvInfo-
> > >pwszContainerName, 200);
> > cbLen++; // Space for ending zero
> > ContainerName = (char*)malloc(cbLen);
> > if (ContainerName == NULL)
> > {
> > *lerrorcode = ERROR_SCM_BUFFER_REALLOC;
> > free(KeyProvInfo);
> > return false;
> > }
> > wcstombs(ContainerName, KeyProvInfo-
> > >pwszContainerName, cbLen);
> >
> > if (KeyProvInfo->pwszProvName == NULL)
> > {
> > ProvName = NULL;
> > }
> > else
> > {
> > cbLen = wcstombs(NULL, KeyProvInfo-
> > >pwszProvName, 200);
> > cbLen++; // Space for ending zero
> > ProvName = (char*)malloc(cbLen);
> > if (ProvName == NULL)
> > {
> > *lerrorcode =
> > ERROR_SCM_BUFFER_REALLOC;
> > free(KeyProvInfo);
> > free(ContainerName);
> > return false;
> > }
> > wcstombs(ProvName, KeyProvInfo-
> > >pwszProvName, cbLen);
> > }
> >
> >
> > DWORD localflag = 0;
> > if(islocal)
> > localflag = CRYPT_MACHINE_KEYSET;
> > //acquisition of the retrieved context
> > if (!CryptAcquireContext(
> >
> > &hProvider,
> >
> > ContainerName,
> >
> > ProvName,
> >
> > KeyProvInfo->dwProvType,
> >
> > localflag))
> > {
> > DWORD err = GetLastError();
> > if(NTE_BAD_KEYSET==err)
> > {
> > if (!CryptAcquireContext(
> >
> > &hProvider,
> >
> > ContainerName,
> >
> > ProvName,
> >
> > KeyProvInfo->dwProvType,
> >
> > CRYPT_NEWKEYSET|localflag))
> > {
> > *lerrorcode =
> > ERROR_SCM_ACQUIRE_CONTXT;
> > free(KeyProvInfo);
> > free(ContainerName);
> > free(ProvName);
> > return false;
> > }
> > }
> > else
> > {
> > *lerrorcode =
> > ERROR_SCM_ACQUIRE_CONTXT;
> > free(KeyProvInfo);
> > free(ContainerName);
> > free(ProvName);
> > return false;
> > }
> > }
> >
> >
> > free(KeyProvInfo);
> > free(ContainerName);
> > free(ProvName);
> >
> >
> > //gets the key from the context
> > if(!CryptGetUserKey(
> > hProvider,
> > // Handle to the CSP
> > AT_KEYEXCHANGE,
> > // Key specification
> > hkey))
> > // Handle to the key
> > {
> > DWORD erro = GetLastError();
> > }
> > *lerrorcode = ERROR_SCM_GET_USERKEY;
> > return false;
> > }
> >
> > return true;
> > }
>
>
- Next message: Merlin Ran: "open device drivers in non-administrator priviledge"
- Previous message: Robert Hoghaug: "Re: Q322047 Does not seem to Work for Enable Themes for non Admin"
- In reply to: Sergio Dutra [MS]: "Re: retrieving certificate's public key"
- Next in thread: Sergio Dutra [MS]: "Re: retrieving certificate's public key"
- Reply: Sergio Dutra [MS]: "Re: retrieving certificate's public key"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|