예제 #1
0
        public static string CreateCAUser2()
        {
            X509Certificate2 cert = new X509Certificate2(CARootPfx, PIN, X509KeyStorageFlags.Exportable);
            var rootKeyPair       = Cert2.ReadPrivateKey(cert);
            var userCert          = Cert2.CreateSelfSignedCertificate("CN=MyUser2CA", "CN=MyROOTCA", rootKeyPair);

            //File.WriteAllText(@"D:\PrivateKey.xml", userCert.PrivateKey.ToXmlString(true));
            //File.WriteAllText(@"D:\PublicKey.xml", userCert.PublicKey.Key.ToXmlString(false));
            byte[] caUserCer = userCert.Export(X509ContentType.Cert, PIN);
            File.WriteAllBytes(CAUser2Cer, caUserCer);
            byte[] caUserPfx = userCert.Export(X509ContentType.Pfx, PIN);
            File.WriteAllBytes(CAUser2Pfx, caUserPfx);
            return(CAUserPfx);
        }
예제 #2
0
        public static void Root2VerifyUserCA()
        {
            try
            {
                X509Certificate2 userCert2 = new X509Certificate2(CAUserPfx, PIN, X509KeyStorageFlags.Exportable);
                var userCert  = DotNetUtilities.FromX509Certificate(userCert2);
                var publicKey = userCert.GetPublicKey();
                //var publicKey = userCert2.PublicKey;
                X509Certificate2 root2Cert2 = new X509Certificate2(CARoot2Pfx, PIN, X509KeyStorageFlags.Exportable);
                var root2KeyPair            = Cert2.ReadPrivateKey(root2Cert2);

                userCert.Verify(root2KeyPair);
            }
            catch (Exception ex)
            {
                //throw;
            }
        }