![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
RSACryptoProvider creation problem: I used some code for RSACryptoProvider creation with smart card and CAPICOM COM object The code worked well in Framework 1.1 but when I tried the same code in Framework 2.0 I got an following Cryptographic exception: "Unable to open the access token of the current thread" string url = string.Empty; rsa = null; certificate = null; RSACryptoServiceProvider.UseMachineKeyStore = true; CspParameters csp = new CspParameters(); csp.Flags = CspProviderFlags.UseMachineKeyStore; ICertificate2 selectedCert = null; //open the ceritificate store Store st = new Store(); st.Open(CAPICOM_STORE_LOCATION.CAPICOM_CURRENT_USE R_STORE, "My", CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_MAXIMUM _ALLOWED); //search for the certificate with the digital signature enabled foreach (ICertificate2 currCert in st.Certificates) { if (currCert.HasPrivateKey()) { selectedCert = currCert; break; } } //check if the certificate was found or not if (selectedCert == null || selectedCert.HasPrivateKey() == false || selectedCert.PublicKey().Algorithm.FriendlyName != "RSA") { StringBuilder sb = new StringBuilder(); sb.Append("Can't find a vaild certificate!\n\n"); sb.Append("Valid Certificate Authorities are :\n"); System.Collections.IEnumerator myEnum = issuerlist.GetEnumerator(); while (myEnum.MoveNext()) sb.Append(myEnum.Current).Append("\n"); throw new Exception(sb.ToString()); } certificate = selectedCert; //create cerificate provider csp.KeyContainerName = selectedCert.PrivateKey.ContainerName; csp.ProviderName = selectedCert.PrivateKey.ProviderName; csp.ProviderType = Convert.ToInt32(selectedCert.PrivateKey.ProviderTy pe); //the certificate key number by the key specifications switch (selectedCert.PrivateKey.KeySpec) { case CAPICOM_KEY_SPEC.CAPICOM_KEY_SPEC_KEYEXCHANGE: csp.KeyNumber = 1; break; case CAPICOM_KEY_SPEC.CAPICOM_KEY_SPEC_SIGNATURE: csp.KeyNumber = 2; break; } //for machine keys use the local store of the machine if (selectedCert.PrivateKey.IsMachineKeyset()) { csp.Flags = CspProviderFlags.UseMachineKeyStore; } //create rsa cryptogragic provider based on the CSP try { rsa = new RSACryptoServiceProvider(csp);//Here i get the Exception } catch { } |
#3
| |||
| |||
|
|
On Feb 28, 8:50 pm, "Joe Kaplan" joseph.e.kap... (AT) removethis (DOT) accenture.com> wrote: I'm not sure what the problem withCAPICOMis, but did you consider converting your code to the new .NET 2.0 X509 stuff? Everything you are doing below is now supported directly by the framework and might be easier to integrate. Joe K. -- Joe Kaplan-MS MVP Directory Services Programming Co-author of "The .NET Developer's Guide to Directory Services Programming"http://www.directoryprogramming.net --<efro... (AT) gmail (DOT) com> wrote in message news:1172675045.093914.251350 (AT) j27g2000cwj (DOT) googlegroups.com... I tried this namespace but there I had similar problem I could not get PrivateKey property of the certificate |
#4
| |||
| |||
|
|
I'm not sure what the problem withCAPICOMis, but did you consider converting your code to the new .NET 2.0 X509 stuff? Everything you are doing below is now supported directly by the framework and might be easier to integrate. Joe K. -- Joe Kaplan-MS MVP Directory Services Programming Co-author of "The .NET Developer's Guide to Directory Services Programming"http://www.directoryprogramming.net --<efro... (AT) gmail (DOT) com> wrote in message news:1172675045.093914.251350 (AT) j27g2000cwj (DOT) googlegroups.com... |
#5
| |||
| |||
|
#6
| |||
| |||
|
|
Yes I used an X509Certificate2 and he has property called HasPrivateKey and its value is true, and yes I checked that certificate in explorer and I saw that there is private key. I have to repeat that code works great in .NET 1.1 |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |