[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ms-cryptoapi
Subject:    Re: Help with CryptoExportKey
From:       Dave Maracchini <Davem () TRISTRATA ! COM>
Date:       1998-03-24 21:54:31
[Download RAW message or body]


        CryptAcquireContext(&hProv, "whynot", MS_DEF_PROV,PROV_RSA_FULL,
CRYPT_NEWKEYSET)
        creates an EMPTY key container (See the docs re
CryptAcquireContext), then see my earlier reply on use of
CryptGetUserKey.

        regards, dave
> -----Original Message-----
> From: Chris Abouzeid [SMTP:chris@SOUNDSTONE.COM]
> Sent: Tuesday, March 24, 1998 8:57 AM
> To:   CryptoAPI@DISCUSS.MICROSOFT.COM
> Subject:      Re: Help with CryptoExportKey
>
> pbKeyBlob is set to NULL.
>
> GetLastError returns a code of 0x80090003. I'm not sure what this
> means,
> assuming the 3 is the most significant part, it means either
> NTE_BAD_FLAGS
> or NTE_BAD_KEY. Don't know why the key would be bad, since it was
> generated
> by the system itself.
>
> --chris
>
> At 01:29 PM 3/24/98 -0800, you wrote:
> >1. It is not apparent from the code that you set pbKeyBlob to NULL
> before the
> >    first call to CryptExportKey.  A nonnull pbKeyBlob would cause an
> error, at
> >    least in debug mode.
> >
> >2. If you meant an exception that your code raised after an error
> return from
> >    CryptExportKey, what was GetLastError() ?
> >
> >Chris Abouzeid wrote:
> >
> >> Help! I am creating an encryption DLL to use with Cold Fusion
> scripting. I
> >> am using C++ V5.0 on an NT 4.0-Service Pack 3 platform and have
> been trying
> >> to get CryptoExportKey to work, but always get an exception. The
> exception
> >> happens when I call CryptoExportKey the first time to get the
> keyblob size.
> >> It doesn't seem to matter whether I try to export the key as a
> SIMPLEBLOB,
> >> PUBLICKEYBLOB, or PRIVATEKEYBLOB.
> >>
> >> Can anyone help me with this? The code is below. (pRequest-> is a
> pointer
> >> to a Cold Fusion structure that handles the exceptions. You can
> ignore it.)
> >>
> >> thanks.
> >>
> >> Chris Abouzeid
> >>
> >> -------------------------------------------------
> >>
> >>         // Get handle to the default provider.
> >>         if(!CryptAcquireContext(&hProv, "whynot", MS_DEF_PROV,
> PROV_RSA_FULL,
> >> NULL)) {
> >>                 if( !CryptAcquireContext(&hProv, "whynot",
> MS_DEF_PROV,
> PROV_RSA_FULL,
> >> CRYPT_NEWKEYSET)) {
> >>
> >>                         pRequest->ThrowException(
> >>                                 "Error during
> CryptAcquireContext!",
> >>                                 "No default provider.");
> >>                         goto done;
> >>                 }
> >>         }
> >>
> >>         // Create block cipher session key.
> >>         if(!CryptGenKey(hProv, CALG_RC2, CRYPT_EXPORTABLE, &hKey))
> {
> >>                 pRequest->ThrowException(
> >>                                 "Error during key creation.",
> >>                                 "Unable to create key.");
> >>             goto done;
> >>         }
> >>
> >>         // Determine size of key blob and allocate memory.
> >>         if(!CryptExportKey(hKey, hXchgKey, PRIVATEKEYBLOB, 0,
> pbKeyBlob,
> >> &dwBlobLen)) {
> >>                 pRequest->ThrowException(
> >>                         "Error exporting key blob.",
> >>                         "CryptExportKey failed");
> >>     }
> >>
> >>         if((pbKeyBlob = (BYTE *)malloc(dwBlobLen)) == NULL) {
> >>                 pRequest->ThrowException(
> >>                         "Error during memory allocation.",
> >>                         "Unable to allocate pbKeyBlob");
> >>         }
> >>
> >>         // Export key into a simple key blob.
> >>         if(!CryptExportKey(hKey, hXchgKey, PRIVATEKEYBLOB, 0,
> pbKeyBlob,
> >> &dwBlobLen)) {
> >>                 pRequest->ThrowException(
> >>                         "Error exporting key blob.",
> >>                         "CryptExportKey failed");
> >>         }
> >>
> >> ----------------------------------------------------------------
> >> Users Guide
> http://www.microsoft.com/sitebuilder/resource/mailfaq.asp
> >> contains important info including how to unsubscribe.  Save time,
> search
> >> the archives at http://microsoft.ease.lsoft.com/archives/index.html
> >
> >
> >
> >
> >
>
> ----------------------------------------------------------------
> Users Guide http://www.microsoft.com/sitebuilder/resource/mailfaq.asp
> contains important info including how to unsubscribe.  Save time,
> search
> the archives at http://microsoft.ease.lsoft.com/archives/index.html

----------------------------------------------------------------
Users Guide http://www.microsoft.com/sitebuilder/resource/mailfaq.asp
contains important info including how to unsubscribe.  Save time, search
the archives at http://microsoft.ease.lsoft.com/archives/index.html

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic