Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 11th, 2004, 07:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Cardiff, , United Kingdom.
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default CryptoAPI Private Key Dialog Box

I am using the Microsoft.Web.Services.Security and System.Security.Cryptography namespaces to access the certificate store and extract a private key from a certificate that I can use for decryption and digital signing.

The problem is that when I request the key a modal dialog box with the caption 'Exporting your private exchange key' is displayed stating that 'An application is requesting access to a protected item.' It states that the protected item is a 'CryptoAPI Private Key.' If the user clicks the OK button then I can use the private key, otherwise a System.Security.Cryptography.CryptographicExceptio n exception is thrown.

I can understand why this dialog box is shown and why I can not access the private key until the user allows me to do so, however I was wondering if there was a way the user could associate their certificate with my application so that they are not requested to allow access to the key every time the app starts. I do not mind the box being displayed the first time they use the certificate however I think it will annoy my user base if they have to click OK every time they start the app.

Here is a simplified example of my code:
Code:
Imports System.Security.Cryptography
Imports Microsoft.Web.Services.Security.X509

Module Module1
    Sub Main()

        Dim store As X509CertificateStore
        Dim cert As X509Certificate
        Dim privateKey As New RSACryptoServiceProvider

        store = X509CertificateStore.LocalMachineStore("My")

        If store.OpenRead() Then
            cert = store.Certificates(0)
            privateKey.FromXmlString(cert.Key.ToXmlString(True))
            'Do some fancy encryption stuff with the private key...
        End If

    End Sub
End Module
Note that this code will only work if you add a reference to the Microsoft.Web.Services.dll and have at least one certificate with a private key in it within the Personal section of the Local Computer certificate store.

Any help here would be greatly appreciated.

Regards
Owain Williams
__________________
Regards
Owain Williams
Reply With Quote
  #2 (permalink)  
Old November 12th, 2004, 11:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Cardiff, , United Kingdom.
Posts: 231
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have found the reason why the dialog box is being displayed, it is because when I imported the certificate into the certificate store I enabled strong private key protection. If this is not enabled then no dialog box is displayed when I extract the private key.

My next question is again regarding the private key. If I do not mark the key as exportable then I can not use it, what is the point of this? I have a private key but I can not use it. Am I accessing the key in a peculiar way? Is there a way of accessing the keys without extracting them from the X509Certificate and importing it into the RSACryptoServiceProvider?

I can not seem to find many details about the CspParameters class that can be used in the constructor for the RSACryptoServiceProvider, does anyone know where I can find more details and if this class would help me gain access to the certificates?

Regards
Owain Williams
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AJAX Dialog Box onlyyourspiyu Ajax 0 May 19th, 2008 08:43 AM
X509 public/private key signing and mmc ZeeKoei General .NET 1 January 23rd, 2008 03:52 AM
Private Key with Associated Certificate bdblhk3 BOOK: Beginning Cryptography with Java 1 October 22nd, 2007 04:32 PM
prob with certificate's public/private key shiby_chacko1@rediffmail. C# 0 April 5th, 2005 07:18 AM
insert dialog box in a dialog box BurhanKhan Visual C++ 7 June 1st, 2004 07:53 PM



All times are GMT -4. The time now is 12:38 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.