Example #1
0
        //CSR
        public static Pkcs10CertificationRequest GenerateCertificateSigningRequest(AsymmetricCipherKeyPair asymmetricCipherKeyPair, Data enrollmentData)
        {
            X509Name x509NameAsSubject = KeyPairHandler.GenerateRelativeDistinguishedName(enrollmentData);

            Asn1SignatureFactory asn1SignatureFactory = new Asn1SignatureFactory("SHA256WithRSA", asymmetricCipherKeyPair.Private);

            return(new Pkcs10CertificationRequest(asn1SignatureFactory, x509NameAsSubject, asymmetricCipherKeyPair.Public, null, asymmetricCipherKeyPair.Private));
        }
Example #2
0
        static void Main(string[] args)
        {
            KeyPairHandler keyPairHandler = new KeyPairHandler();
            Data           enrollmentData = new Data();

            //initialize safeNet .dll .
            //put your .dll file inside x64 or x32 folder.
            //keep these folders in *.exe's folder
            if (Environment.Is64BitProcess)
            {
                Constants.PKCS11_LIBRARY_PATH = @"x64\eTPKCS11.dll";
            }
            else
            {
                Constants.PKCS11_LIBRARY_PATH = @"x32\eTPKCS11.dll";
            }

            //need to implement
            PopulateEnrollmentData(out enrollmentData);

            String generationMode = Console.ReadLine();

            switch (generationMode)
            {
            case "certificate":
                X509Certificate x509Certificate = CertificateHandler.CertificateGenerator(enrollmentData.ID);
                //write certificate to smart card
                CertificateHandler.ImportCertificateToSmartCard(x509Certificate);
                break;

            case "key":
                // RSA 2048
                AsymmetricCipherKeyPair asymmetricCipherKeyPair = KeyPairHandler.GenerateKeyPair();
                // CSR
                Pkcs10CertificationRequest csr = KeyPairHandler.GenerateCertificateSigningRequest(asymmetricCipherKeyPair, enrollmentData);
                //need to implement
                GenerationRequestToServerForDotP7B();
                //private key write to smart card(safeNet e-Token)
                KeyPairHandler.ImportPrivateKeyToSmartCard(asymmetricCipherKeyPair, enrollmentData);
                break;
            }

            Console.ReadKey();
        }