Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 11th, 2004, 07:09 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old November 12th, 2004, 11:49 AM
Friend of Wrox
 
Join Date: Jun 2003
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





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





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