public void CreateWithDefaultOptions()
        {
            var cert = RSACertificateBuilder.CreateNewCertificate("Test");

            Assert.AreEqual("CN=Test", cert.Subject);
            Assert.AreEqual("sha256RSA", cert.SignatureAlgorithm.FriendlyName);
            Assert.IsTrue(cert.HasPrivateKey);
        }
Example #2
0
        public void CanCreateWithPublicKeyOnly()
        {
            var cert = RSACertificateBuilder.CreateNewCertificate(new RSACertificateBuilderOptions {
                FullSubjectName = "CN=Test", KeySize = 1024
            });
            var publicCert = new X509Certificate2(cert.Export(X509ContentType.Cert));

            var blob = AESBlob.CreateBlob(AESKeySize.AES256, publicCert);
        }
Example #3
0
            public void PublicKeyOnlyCorrectlyParses()
            {
                var cert       = RSACertificateBuilder.CreateNewCertificate("Test");
                var data       = cert.Export(X509ContentType.Cert);
                var publicCert = new X509Certificate2(data);

                var cng = RSACertificateParser.ParsePublicCertificate(publicCert);

                Assert.IsNotNull(cng);
            }
Example #4
0
            public void NoPublicKeyThrowsError()
            {
                Assert.Throws(typeof(InvalidOperationException), () =>
                {
                    var cert       = RSACertificateBuilder.CreateNewCertificate("Test");
                    var data       = cert.Export(X509ContentType.Cert);
                    var publicCert = new X509Certificate2(data);

                    RSACertificateParser.ParsePrivateCertificate(publicCert);
                });
            }
Example #5
0
        public void AES192CreatesWorkableKey()
        {
            var cert = RSACertificateBuilder.CreateNewCertificate(new RSACertificateBuilderOptions {
                FullSubjectName = "CN=Test", KeySize = 1024
            });
            var blob      = AESBlob.CreateBlob(AESKeySize.AES192, cert);
            var encryptor = AESBlob.CreateEncryptor(blob, cert);

            var data = Encoding.UTF8.GetBytes("Super secret secret");

            encryptor.Encrypt(data);
        }
Example #6
0
            public void KeySize2048CertificateCorrectlyParses()
            {
                var options = new RSACertificateBuilderOptions
                {
                    FullSubjectName = "CN=Test",
                    KeySize         = 2048
                };

                var cert = RSACertificateBuilder.CreateNewCertificate(options);
                var cng  = RSACertificateParser.ParsePublicCertificate(cert);

                Assert.IsNotNull(cng);
            }
Example #7
0
        public void CannotDecrpytWithoutPrivateKey()
        {
            Assert.Throws(typeof(InvalidOperationException), () =>
            {
                var cert = RSACertificateBuilder.CreateNewCertificate(new RSACertificateBuilderOptions {
                    FullSubjectName = "CN=Test", KeySize = 1024
                });
                var publicCert = new X509Certificate2(cert.Export(X509ContentType.Cert));

                var blob = AESBlob.CreateBlob(AESKeySize.AES256, publicCert);
                AESBlob.CreateEncryptor(blob, publicCert);
            });
        }
        public void CreateWithSha512Hash()
        {
            var options = new RSACertificateBuilderOptions
            {
                FullSubjectName = "CN=Test",
                HashingMethod   = HashingMethods.Sha512
            };

            var cert = RSACertificateBuilder.CreateNewCertificate(options);

            Assert.AreEqual("CN=Test", cert.Subject);
            Assert.AreEqual("sha512RSA", cert.SignatureAlgorithm.FriendlyName);
            Assert.IsTrue(cert.HasPrivateKey);
        }
        public void CreateWith7168KeySize()
        {
            var options = new RSACertificateBuilderOptions
            {
                FullSubjectName = "CN=Test",
                KeySize         = 7168
            };

            var cert = RSACertificateBuilder.CreateNewCertificate(options);

            Assert.AreEqual("CN=Test", cert.Subject);
            Assert.AreEqual("sha256RSA", cert.SignatureAlgorithm.FriendlyName);
            Assert.IsTrue(cert.HasPrivateKey);
        }