コード例 #1
0
ファイル: FolaighKeyStoreTest.cs プロジェクト: flann/Folaigh
        private FolaighKeyGenerator generateKeys()
        {
            FolaighKeyGenerator keyGenerator = new FolaighKeyGenerator();

            keyGenerator.KeySize   = 1024;
            keyGenerator.Certainty = 8;
            keyGenerator.createKeyPair("US", "Karmashave", "Salt Lake City",
                                       "Utah", EMAIL_ADDRESS, "Foo");
            return(keyGenerator);
        }
コード例 #2
0
ファイル: FolaighKeyStoreTest.cs プロジェクト: flann/Folaigh
        /**
         * FolaighKeyStore has a method to add just a certificate (public key)
         *
         */
        public void testAddCertificate()
        {
            FolaighKeyGenerator keyGenerator = generateKeys();
            FolaighKeyStore     keyStore     = getKeyStore();
            string alias = "fooKey";

            keyStore.addCertificate(alias, keyGenerator.Certificate);
            Assert.IsNull(keyStore.getPrivateKey(alias));
            Assert.IsNotNull(keyStore.getCertificate(alias));
        }
コード例 #3
0
        public void testGenerateKeyPair()
        {
            string country         = "US";
            string organization    = "KarmaShave";
            string locality        = "Salt Lake City";
            string stateOrProvince = "Utah";
            string emailAddress    = "*****@*****.**";
            string commonName      = "Terry";

            FolaighKeyGenerator keyGenerator = new FolaighKeyGenerator();

            Assert.IsNull(keyGenerator.Certificate);
            Assert.IsNull(keyGenerator.PrivateKey);
            keyGenerator.KeySize   = 1024;
            keyGenerator.Certainty = 8;
            keyGenerator.createKeyPair(country, organization, locality, stateOrProvince, emailAddress, commonName);
            Assert.IsNotNull(keyGenerator.Certificate.GetType());
            Assert.IsNotNull(keyGenerator.PrivateKey);
        }
コード例 #4
0
ファイル: FolaighKeyStoreTest.cs プロジェクト: flann/Folaigh
        /**
         * FolaighKeyStore can export a certificate to a DER-encoded base-64 string
         *
         */
        public void testExportCertificate()
        {
            FolaighKeyGenerator keyGenerator = generateKeys();
            FolaighKeyStore     keyStore     = getKeyStore();
            string alias = "fooKey";

            keyStore.addKey(alias, keyGenerator.PrivateKey, keyGenerator
                            .Certificate);
            Object o = null;

            o = keyStore.exportCertificate(alias);
            Assert.IsNotNull(o);
            Assert.IsTrue(o is string);
            string          encodedCertificate = (string)o;
            X509Certificate certificate        = getX509CertificateFromEncodedString(encodedCertificate);

            Assert.AreEqual(
                Convert.ToBase64String(keyStore.getCertificate(alias).getEncoded()),
                Convert.ToBase64String(certificate.getEncoded()));
        }