/** * FolaighKeyStore can import a certificate from a base-64 DER-encoded * string. When the certificate is imported, it uses the email field in the * certificate as an alias. If the email field is not set, it uses the * common name. */ public void testImportCertificate() { FolaighKeyStore keyStore = getKeyStore(); X509Certificate expectedCertificate = getX509CertificateFromEncodedString(base64EncodedCertificate); keyStore.importCertificate(base64EncodedCertificate); Assert.IsNotNull(keyStore.getCertificate(EMAIL_ADDRESS)); Assert.AreEqual(expectedCertificate.getEncoded(), keyStore.getCertificate(EMAIL_ADDRESS).getEncoded()); }
/** * 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)); }
/** * 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())); }