Error During Cryptacquirecontext For A New Key
Contents |
Studio 2015 products Visual Studio Team Services Visual Studio Code Visual
Cryptacquirecontext Example
Studio Dev Essentials Office Office Word/Excel/PowerPoint Microsoft Graph cryptacquirecontext c# Outlook OneDrive/Sharepoint Skype Services Store Cortana Bing Application Insights Languages & platforms Xamarin cryptacquirecontext fails ASP.NET C++ TypeScript .NET - VB, C#, F# Server Windows Server SQL Server BizTalk Server SharePoint Dynamics Programs & communities Students Startups
Cryptacquirecontexta
Forums MSDN Subscriber downloads Sign in Search Microsoft Search Windows Dev Center Windows Dev Center Explore What’s new for Windows 10 Intro to Universal Windows Platform Coding challenges Develop for accessibility Build for enterprise Windows Store opportunities Docs Windows apps Get started Design and
Cryptacquirecontext Failed Windows 7
UI Develop API reference Publish Monetize Promote Games Get started UI design Develop Publish Desktop Get started Design Develop API reference Test and deploy Compatibility Windows IoT Microsoft Edge Windows Holographic Downloads Samples Support Why Windows Dashboard Explore What’s new for Windows 10 Intro to Universal Windows Platform Coding challenges Develop for accessibility Build for enterprise Windows Store opportunities Docs Windows apps Get started Design and UI Develop API reference Publish Monetize Promote Games Get started UI design Develop Publish Desktop Get started Design Develop API reference Test and deploy Compatibility Windows IoT Microsoft Edge Windows Holographic Downloads Samples Support Why Windows Dashboard Cryptography Cryptography Reference Cryptography Functions Cryptography Functions CryptAcquireContext CryptAcquireContext CryptAcquireContext CertAddCertificateContextToStore CertAddCertificateLinkToStore CertAddCRLContextToStore CertAddCRLLinkToStore CertAddCTLContextToStore CertAddCTLLinkToStore CertAddEncodedCertificateToStore CertAddEncodedCertificateToSystemStore CertAddEncodedCRLToStore CertAddEncodedCTLToStore CertAddEnhancedKeyUsageIdentifier CertAddRefServerOcspResponse CertAddRefServerOcspResponseContext CertAddSerializedElementToStore CertAddStoreToCollection
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings cryptacquirecontext nte_bad_keyset and policies of this site About Us Learn more about Stack Overflow
Prov_rsa_full
the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation crypt_verifycontext Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it https://msdn.microsoft.com/en-us/library/windows/desktop/aa379886(v=vs.85).aspx only takes a minute: Sign up CryptoAPI AcquireContext fails to retrieve key container up vote 2 down vote favorite I am porting an old vb6 application to .net and I am having an issue since yesterday afternoon with some CryptoAPI calls. In particular I can't retrieve a key container which is already defined. I use the CryptAcquireContext() function. I use some http://stackoverflow.com/questions/15945218/cryptoapi-acquirecontext-fails-to-retrieve-key-container test code where I create the container. Then If I go to C:\Users...\Roaming\Microsoft\Crypto\RSA\Machine Keys\ I can see a file created with my defined container name inside so I assume it's created successfully. A subsequent call to try creating the same container verifies that assumption because I get the win32 error that the keyset is already defined. Anyway on my next code call where I try to retrieve the container I already created I get the windows error that the keyset is not defined. Error : -2146893799 (80090019) The keyset is not defined. Any ideas? Here's a code example : public const uint PROV_RSA_FULL = 1; public const uint CRYPT_NEWKEYSET = 0x00000008; public const uint CRYPT_MACHINE_KEYSET = 0x00000020; const string MS_DEF_PROV = "Microsoft Base Cryptographic Provider v1.0"; [DllImport("advapi32.dll", SetLastError = true)] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool CryptAcquireContext(out IntPtr phProv, string pszContainer, string pszProvider, uint dwProvType, uint dwFlags); public static void CreateContainer() { IntPtr hCryptProv; int error; if (!CryptAcquireContext(out hCryptProv, "new", MS_DEF_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET)) { error = Marshal.GetLastWin32Error(); } if (!CryptAcquireContext(out hCryptProv, "new", MS_DEF_PROV, PROV_RSA_FULL, CRYPT_MACHINE_KEYSET)) { error = Marshal.Get
Many moons ago I created an encryption dll for our company website. This dll was created in VB6 and using the CryptoAPI. OK, so I cheated http://www.jorriss.net/2004/10/22/cryptoapi-and-the-headaches-that-it-caused/ a bit and used some encryption code that was created by Fredrik Qvarfort. But why reinvent the wheel? Or the CryptoAPI calls? Anyways, during a routine security patch deployment the encryption dll on one of the servers stopped working. The funny thing was it was working fine on the other machines. So we reinstalled the web application, uninstalled and reinstalled the COM error during dlls as well as some system dlls. But the dll was still not working. So I had to do what I didn't want to do, write some debug code. I cracked open VB6 and wondered where all my intellisense, formatting and inline help went. But after a few minutes it all came back. Like an old glove, worn but it still fits. The error during cryptacquirecontext problem stemmed from the CryptAcquireContext function call. The CryptAcquireContext function gets a handle to the key container (where the keys are stored). Here is the code we were using: ‘Get handle to CSP If (CryptAcquireContext(hCryptProv, KEY_CONTAINER, SERVICE_PROVIDER, PROV_RSA_FULL, CRYPT_MACHINE_KEYSET) = 0) Then If (CryptAcquireContext(hCryptProv, KEY_CONTAINER, SERVICE_PROVIDER, PROV_RSA_FULL, CRYPT_MACHINE_KEYSET + CRYPT_NEWKEYSET) = 0) Then Call Err.Raise(vbObjectError + Err.LastDllError, , "CryptAcquireContext - " & DetermineError(Err.LastDllError)) End If End If The first call to CryptAcquireContext attempts to gain access to an existing key container. The second attempts to create a new container if it cannot find the existing key container. The first call was giving me an error of -2146893802. The second call was sending an error of -2146893809. Big help. Luckily, Microsoft has a KB article on translating automation errors for VB. I was able to cross reference the error hex codes with another KB titled CryptAcquireContext() use and troubleshooting. And there is where I found my Rosetta Stone. Turns out that the errors -2146893802 (0x80090016 or NTE_BAD_KEYSET) and -2146893809 (0x80090019 or NTE_EXISTS) together implies that access to the key container is denied. Great! But where a