Exemplo n.º 1
0
        } // End Function GenerateCertificate

        static bool ValidateSelfSignedCert(
            Org.BouncyCastle.X509.X509Certificate cert,
            Org.BouncyCastle.Crypto.ICipherParameters pubKey
            )
        {
            cert.CheckValidity(System.DateTime.UtcNow);
            byte[] tbsCert = cert.GetTbsCertificate(); // (TBS is short for To Be Signed), see RFC5280 for all the gory details.
            byte[] sig     = cert.GetSignature();

            Org.BouncyCastle.Crypto.ISigner signer = Org.BouncyCastle.Security.SignerUtilities.GetSigner(
                cert.SigAlgName
                );

            signer.Init(false, pubKey);
            signer.BlockUpdate(tbsCert, 0, tbsCert.Length);
            return(signer.VerifySignature(sig));
        } // End Function ValidateSelfSignedCert
Exemplo n.º 2
0
        public static void RootVerifyUserCA()
        {
            try
            {
                X509Certificate2 userCert2 = new X509Certificate2(CAUserPfx, PIN, X509KeyStorageFlags.Exportable);
                X509Certificate  userCert  = DotNetUtilities.FromX509Certificate(userCert2);
                userCert2.p
                var userKeyPair = userCert.GetPublicKey();
                //var publicKey = userCert2.PublicKey;
                X509Certificate2 rootCert2 = new X509Certificate2(CARootPfx, PIN, X509KeyStorageFlags.Exportable);
                //var rootKeyPair = Cert2.ReadPrivateKey(rootCert2);
                var add         = Cert2.AddCertToStore(rootCert2, StoreName.Root, StoreLocation.LocalMachine);
                var rootCert    = DotNetUtilities.FromX509Certificate(userCert2);
                var rootKeyPair = rootCert.GetPublicKey();

                //rootCert.Verify(userKeyPair);
                var a = Cert2.VerifySha2(rootCert2, userCert.GetEncoded(), userCert.GetSignature());
            }
            catch (Exception ex)
            {
                //throw;
            }
        }