@Test public void testPrivateKey() throws Exception { KeyPair keyPair = KeyPairFactory.newRsa2048(); String pem = PemUtils.toPem(keyPair.getPrivate()); assertNotNull(pem); PrivateKey privateKey = PemUtils.loadPrivateKeyFromPem(pem); assertTrue(privateKey.getAlgorithm().equalsIgnoreCase(BcCmsConstants.KEY_PAIR_ALGO)); }
@Test public void testCert() throws Exception { CertificateFactory certFactory = new BcCertificateFactory(); KeyPair keyPair = KeyPairFactory.newRsa2048(); X509Certificate cert = certFactory.newCertificate(keyPair, "study"); String pem = PemUtils.toPem(cert); assertNotNull(pem); cert = PemUtils.loadCertificateFromPem(pem); cert.checkValidity(); cert.verify(keyPair.getPublic(), BcCmsConstants.PROVIDER); }