Пример #1
0
        static void Main(string[] args)
        {
            Authorities();
            return;

            SimpleSerialNumber       seq = new SimpleSerialNumber();
            X509CertificateAuthority ca  = X509CertificateAuthority.SelfSigned(
                seq,
                new X509Name("CN=."),
                TimeSpan.FromDays(10)
                );

            Console.WriteLine(ca.Certificate);

            DSA         dsa = new DSA(new DSAParameters(512));
            CryptoKey   key = new CryptoKey(dsa);
            X509Request req = new X509Request(0, new X509Name("CN=com."), key);

            req.Sign(key, MessageDigest.DSS1);

            X509Certificate cert = ca.ProcessRequest(req, TimeSpan.FromDays(10));

            Console.WriteLine(cert);
            Console.WriteLine("CA Verified: " + cert.Verify(ca.Key));
            Console.WriteLine("Self Verified: " + cert.Verify(key));

            SimpleSerialNumber       serial2 = new SimpleSerialNumber();
            X509CertificateAuthority caSelf  = new X509CertificateAuthority(
                cert,
                key,
                serial2);

            X509Request req2    = cert.CreateRequest(key, MessageDigest.DSS1);
            X509Name    subject = req2.Subject;

            Console.WriteLine("Request1: " + req);
            Console.WriteLine("Request2: " + req2);

            X509Certificate cert2 = caSelf.ProcessRequest(req2, TimeSpan.FromDays(10));

            Console.WriteLine("Cert2: " + cert2);

            DH dh = new DH(128, 5);

            MessageDigestContext mdc = new MessageDigestContext(MessageDigest.DSS1);

            byte[] msg = dh.PublicKey;
            byte[] sig = mdc.Sign(msg, key);

            Console.WriteLine(dh);
            Console.WriteLine("DH P         : " + BitConverter.ToString(dh.P));
            Console.WriteLine("DH G         : " + BitConverter.ToString(dh.G));
            Console.WriteLine("DH Secret Key: " + BitConverter.ToString(dh.PrivateKey));
            Console.WriteLine("DH Public Key: " + BitConverter.ToString(msg));
            Console.WriteLine("DH Signature : " + BitConverter.ToString(sig));

            Console.WriteLine(mdc.Verify(msg, sig, key));
        }
Пример #2
0
        public void CanCreateRequest()
        {
            DateTime  start = DateTime.Now;
            DateTime  end   = start + TimeSpan.FromMinutes(10);
            CryptoKey key   = new CryptoKey(new DSA(true));

            using (X509Certificate cert = new X509Certificate(101, "CN=localhost", "CN=Root", key, start, end)) {
                X509Request request = cert.CreateRequest(key, MessageDigest.DSS1);
                Assert.AreEqual(true, request.Verify(key));
            }
        }
Пример #3
0
		public void CanCreateRequest()
		{
			var start = DateTime.Now;
			var end = start + TimeSpan.FromMinutes(10);
			using (var key = new CryptoKey(new DSA(true)))
			using (var cert = new X509Certificate(101, "CN=localhost", "CN=Root", key, start, end))
			using (var request = cert.CreateRequest(key, MessageDigest.DSS1))
			{
				Assert.IsTrue(request.Verify(key));
			}
		}
Пример #4
0
		public void CanCreateRequest()
		{
			DateTime start = DateTime.Now;
			DateTime end = start + TimeSpan.FromMinutes(10);
			CryptoKey key = new CryptoKey(new DSA(true));
			using (X509Certificate cert = new X509Certificate(101, "CN=localhost", "CN=Root", key, start, end)) {
				X509Request request = cert.CreateRequest(key, MessageDigest.DSS1);
				Assert.AreEqual(true, request.Verify(key));
			}
		}
Пример #5
0
		public void CanCreateRequest()
		{
			var start = DateTime.Now;
			var end = start + TimeSpan.FromMinutes(10);
			using (var key = new CryptoKey(new DSA(true)))
			using (var cert = new X509Certificate(101, "CN=localhost", "CN=Root", key, start, end))
			using (var request = cert.CreateRequest(key, MessageDigest.DSS1))
			{
				Assert.IsTrue(request.Verify(key));
			}
		}