microsoft.web.services2.dll Key error when decrypting with Private key from local store

From: Rich Schaefer (SomeOne_at_SomeWhere.com)
Date: 07/21/05

  • Next message: jason: "Help plz!!! Authenticate user again active directory"
    Date: Thu, 21 Jul 2005 01:02:23 GMT
    
    

       I am using microsoft.web.services2.dll so that I can access the Certificate stores.
       When I try to Decrypy a buffer using the RSACryptoServiceProvider.Decrypy method
       I get a bad key error. The Certificate is self signed (made with makecert.exe). Looks OK
       when I look at it in Explore.exe The following is my guts of my code:

       A little description: A Collection of encrypted files. The RSA encrypted AES keys
       for the encrypted files are in the Collection with names equal to the Certificate hash
       used to encrpt (Of course using the Cert Public key) the AES keys.

       byte[] EncodedBuffer = null;
       X509Certificate Cert;
       X509CertificateStore store;
       store = X509CertificateStore.CurrentUserStore(X509CertificateStore.MyStore);
       bool open = store.OpenRead();

       // The following is to find the Certificate and Data to Decrypt
       // From my many Personal Certificats

       X509CertificateCollection Certs = store.Certificates;
       for (int i = 0; i < Certs.Count; i++) {
         Cert = Certs[i];
         HashCode = Cert.GetCertHashString();
         if (m_ZipFile.Lookup(HashCode) != null) {
           EncodedBuffer = m_ZipFile.GetData(HashCode);
           s_DecryptCertificate = Cert;
           break;
         }
       }
       store.Close();

       if (EncodedBuffer != null) {
         Microsoft.Web.Services2.Security.Cryptography.RSACryptoServiceProvider sp =
           (Microsoft.Web.Services2.Security.Cryptography.RSACryptoServiceProvider)
           Cert.Key;

         RSACryptoServic sp = (RSACryptoServiceProvider) Cert.Key;
         byte[] DecodedBuffer = sp.Decrypt(EncodedBuffer, false);

         ...


  • Next message: jason: "Help plz!!! Authenticate user again active directory"

    Relevant Pages

    • Web Service Call Using Digital Certificates
      ... MyWebService myService = new MyWebService; ... ASP.NET application that I am running under this account. ... The Root CA certificate is installed under the "Current User" and the "Local ... Computer" certificate stores and the client certificate is installed in both ...
      (microsoft.public.dotnet.framework.aspnet.webservices)
    • Re: how to creat a certificate
      ... certificates and certificate stores currently (this evidently is coming ... You can create RSA keypairs automatically with .net framework ... Note that if you have already generated a keycontainer, ...
      (microsoft.public.security)
    • Re: help me in understanding CAPI
      ... thereare certificate system stores on your machine like root, ca,trust etc. ... CSP associated with it? ... > Question3) CSP's are supposed to have key containers correct? ... of certificate stores. ...
      (microsoft.public.platformsdk.security)
    • Web Service Call Using Digital Certificates
      ... I am currently having a problem calling a web service that is secured using ... I set up a Windows application to make a call to the ... The Root CA certificate is installed under the "Current User" and the "Local ... Computer" certificate stores and the client certificate is installed in both ...
      (microsoft.public.dotnet.framework.aspnet)
    • PKCS #7 detached signature
      ... // System Certificate store handle. ... PCCERT_CONTEXT pSignerCert; ... // The length of the signed and encoded message. ... // Buffer to hold the name of the subject of a certificate. ...
      (microsoft.public.platformsdk.security)