Exemple #1
0
        private X509SecurityToken getToken(string which)
        {
            X509SecurityToken    token = null;
            X509CertificateStore store = null;

            string serverKeyIdentifier = "bBwPfItvKp3b6TNDq+14qs58VJQ=";             //"po3h4Y4J8ITs/pW3acuRjpT8V1o=";
            string clientKeyIdentifier = "gBfo0147lM6cKnTbbMSuMVvmFY4=";             //"Gu4aD7+bYTVtmSveoPIWTRtzD3M=";

            //string serverKeyIdentifier = "po3h4Y4J8ITs/pW3acuRjpT8V1o=";
            //string clientKeyIdentifier = "Gu4aD7+bYTVtmSveoPIWTRtzD3M=";

            store = X509CertificateStore.LocalMachineStore(X509CertificateStore.MyStore);
            store.OpenRead();
            X509CertificateCollection coll;

            if (which == "server")
            {
                coll = store.FindCertificateByKeyIdentifier(Convert.FromBase64String(serverKeyIdentifier));
            }
            else
            {
                coll = store.FindCertificateByKeyIdentifier(Convert.FromBase64String(clientKeyIdentifier));
            }

            if (coll.Count > 0)
            {
                X509Certificate cert = (X509Certificate)coll[0];
                RSA             rsa  = cert.Key;
                token = new X509SecurityToken(cert);
            }
            return(token);
        }
        private static X509SecurityToken RetrieveTokenFromStore(X509CertificateStore store, string keyIdentifier)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            X509SecurityToken token = null;

            try
            {
                if (store.OpenRead())
                {
                    // Place the key ID of the certificate in a byte array
                    // This KeyID represents the Wse2Quickstart certificate included with the WSE 2.0 Quickstarts
                    // ClientBase64KeyId is defined in the ClientBase.AppBase class
                    X509CertificateCollection certs = store.FindCertificateByKeyIdentifier(Convert.FromBase64String(keyIdentifier));

                    if (certs.Count > 0)
                    {
                        // Get the first certificate in the collection
                        token = new X509SecurityToken(((X509Certificate)certs[0]));
                    }
                }
            }
            finally
            {
                if (store != null)
                {
                    store.Close();
                }
            }

            return(token);
        }
      private static X509SecurityToken RetrieveTokenFromStore (X509CertificateStore store, string keyIdentifier) 
	{
	  if (store == null)
	    throw new ArgumentNullException ("store");
	  X509SecurityToken token = null;
	  try 
	    {
	      if (store.OpenRead ())
		{
		  // Place the key ID of the certificate in a byte array
		  // This KeyID represents the Wse2Quickstart certificate included with the WSE 2.0 Quickstarts
		  // ClientBase64KeyId is defined in the ClientBase.AppBase class
		  X509CertificateCollection certs =
		      store.FindCertificateByKeyIdentifier (Convert.FromBase64String (keyIdentifier));
		  if (certs.Count > 0)

		    {
		      // Get the first certificate in the collection
		      token = new X509SecurityToken (((X509Certificate) certs[0]));
		    }
		}
	    }
	  finally 
	    {
	      if (store != null)
		store.Close ();
	    }
	  return token;
	}