コード例 #1
0
        private static WrappedResponse <CreateCertificateOutType> CreateCertificates(PKIClient client, string pin, CertStore store)
        {
            var myLoadedCryptoCert  = store.GetCertificate(CertStore.Certificiates.ClientGeneratedEncryption);
            var myLoadedSigningCert = store.GetCertificate(CertStore.Certificiates.ClientGeneratedSigning);


            var res = client.CreateCertificate(myLoadedSigningCert, myLoadedCryptoCert, pin, KeyGeneratorTypeType.software);

            if (!CheckForError(res))
            {
                return(null);
            }

            return(res);
        }
コード例 #2
0
        private static CreateCertificateResponse CreateCertificates()
        {
            Console.WriteLine("Loading own certificates ...");
            var myLoadedCryptoCert  = CertStore.GetCertificate(CertStore.Certificiates.ClientGeneratedEncryption);
            var myLoadedSigningCert = CertStore.GetCertificate(CertStore.Certificiates.ClientGeneratedSigning);

            if (myLoadedCryptoCert == null || myLoadedSigningCert == null)
            {
                Console.WriteLine("Client generated certificates and private keys were not set in certificate CertStore.");
                Console.WriteLine("Please set the encryption and signing certificates in the \"DanskeBank.PKIFactory\" CertStore using the friendlyname names:");
                Console.WriteLine("  Signing: \"" + CertStore.Certificiates.ClientGeneratedSigning.ToString() + "\".");
                Console.WriteLine("  Encryption: \"" + CertStore.Certificiates.ClientGeneratedEncryption.ToString() + "\".");
                exitProgram(1);
                return(null);
            }

            Console.WriteLine("Sending certificate signing requests for own certificates ...");
            var res = PKIClient.CreateCertificate(myLoadedSigningCert, myLoadedCryptoCert, CustomerPIN, KeyGeneratorTypeType.software);

            if (!CheckForError(res))
            {
                exitProgram(Int32.Parse(res.Error.ReturnCode));
                return(null);
            }

            // Read the x509 certificates returned from the server
            var issuedCryptoCert  = new X509Certificate2(res.Response.CreateCertificateResponse.EncryptionCert);
            var issuedSigningCert = new X509Certificate2(res.Response.CreateCertificateResponse.SigningCert);

            // Set the private key on the X509Certificate2 instances, so we can easily CertStore them
            issuedCryptoCert.PrivateKey  = myLoadedCryptoCert.PrivateKey;
            issuedSigningCert.PrivateKey = myLoadedSigningCert.PrivateKey;

            // Save the issued certificataes
            CertStore.SetCertificate(CertStore.Certificiates.ClientIssuedEncryption, issuedCryptoCert.Export(X509ContentType.Pkcs12));
            CertStore.SetCertificate(CertStore.Certificiates.ClientIssuedSigning, issuedSigningCert.Export(X509ContentType.Pkcs12));

            Console.WriteLine("  Certificates created successfully.");
            return(res.Response.CreateCertificateResponse);
        }