RE: CryptGetUserKey fails with 8009000d

From: lelteto (lelteto_at_discussions.microsoft.com)
Date: 09/18/05

  • Next message: Duane: "Re: WinInet -- Disable SSL Checks for Invalid CA?"
    Date: Sat, 17 Sep 2005 16:19:02 -0700
    
    

    GetUserKey returns key handle to either the AT_SIGNATURE or AT_KEYEXCHANGE
    keyPAIR in the given container. When you import a PUBLIC key it is not
    associated with either - it is just a 'temporary' key. (If you generate or
    import a secret key you would also get just temporary keys - and they cannot
    be retrieved with CryptGetUserKey.) Within the SAME session you would just
    have to use the key handle returned by the CryptImport function. Since
    temporary keys are NOT saved (once you closed the context handle with
    CryptReleaseContext) next time you need the same key you have to re-import it
    again. In fact, if you just need to import the public key than you can simple
    use a temp crypto context by calling CryptAcquireContext with
    CRYPT_VERIFYCONTEXT.

    Laszlo Elteto
    SafeNet, Inc.

    "Daniel" wrote:

    > Hi All.
    >
    > I have written a Active X DLL in VB to take care of some cryptography
    > functions I need performed by my ASP app (actually it modifies a nice little
    > class I found somewhere.)
    >
    > The only functions I need the DLL to perform are impoting and signing
    > strings with a private key and importing a public key and encrypting
    > strings.
    >
    > The first problem I had was getting CryptAcquireContext to work on the
    > TARGER SERVER because the security context that the application was running
    > in did not have access to a use profile. Thanks to Microsoft Q238187 I was
    > able to get a container like so:
    >
    > '
    > ' try to acquire the existing container
    > '
    > lngReturnValue = CryptAcquireContext(hCryptProv, "Container" & vbNullChar,
    > SERVICE_PROVIDER, PROV_RSA_FULL, _
    > CRYPT_MACHINE_KEYSET)
    > If lngReturnValue = 0 Then
    > '
    > ' Try to make a new key container
    > '
    > lngReturnValue = CryptAcquireContext(hCryptProv, "Container" &
    > vbNullChar, SERVICE_PROVIDER, PROV_RSA_FULL, _
    > CRYPT_NEWKEYSET Or
    > CRYPT_MACHINE_KEYSET)
    > If lngReturnValue = 0 Then Err.Raise Err.LastDllError, , "DLL error
    > code shown above. Error during CryptAcquireContext for a new key container."
    > End If
    >
    > The first call succeeds. I am never able to successfully make a new
    > container.
    >
    > However after that I am able to successfully call decrypt and import the
    > signature key (using CryptImportKey) and use it to sign some text ( using
    > CryptCreateHash and CryptSignHash)
    > there is no problem.
    >
    > The problem arises when I attempt to import a Public Encryption key.
    > CryptImportKey succeeds fine, but CryptGetUserKey fails with error 8009000d.
    >
    > I think the problem obviously has something to do with Calling
    > CryptAcquireContext with CRYPT_MACHINE_KEYSET.
    >
    > If I edit the account used for anonymous access on the page and set it to an
    > account that is logged in (like mine) then I don't need to use
    > CRYPT_MACHINE_KEYSET I can create a new
    > container with CRYPT_NEWKEYSET and everything works fine.
    >
    > Any help would be greatly appreciated.
    >
    >
    > --
    > Daniel
    >
    >
    >


  • Next message: Duane: "Re: WinInet -- Disable SSL Checks for Invalid CA?"

    Relevant Pages

    • Re: Using the Public Key embedded in the Assembly?
      ... amongst them a keyblob parser. ... well that the keypair I retrieve from the container is not the same as the ... > approach you've been trying to get the private key out of the CSP is not ... >> the digest) with your public key, ...
      (microsoft.public.dotnet.security)
    • Re: Using the Public Key embedded in the Assembly?
      ... assembly and to embed the public key in the assembly. ... When I send the assembly to a customer (together with the license file), ... and no csp container with such name and content exists on the machine of the ... > ImportCspBlob method on RSACryptoServiceProvider, ...
      (microsoft.public.dotnet.security)
    • Re: Strong Named Key Files - Deployment
      ... This has shed a lot of light on the subject, and raised a couple more questions, I hope I don't sound too stupid, but what is a container, and how do they work? ... container in the local CSP and then use the AssemblyKeyName attribute ... sn.exe -i mywebapp.snk mywebapp ... but you might want to publish your public key. ...
      (microsoft.public.dotnet.distributed_apps)
    • RE: CryptExportKey questions
      ... You normally export a public key wrapped with a SYMMETRIC key (eg. AES ... or generate within the container (eg. ... you would need the handles within the same CSP. ... set hExpKey to NULL. ...
      (microsoft.public.platformsdk.security)
    • Re: [RFC][PATCH 1/5] Virtualization/containers: startup
      ... One is owner of a task, 2nd is a current context. ... exec_env pointer is used to avoid adding of additional argument to all the ... That's why "container" would be a lot better. ... current->econtainer - effective container ...
      (Linux-Kernel)