@Test
public void testExportKeyPair() throws CMException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException {

	String alias = credentialManager.addKeyPair(privateKey, privateKeyCertChain);
	File fileToExportTo = new File(credentialManagerDirectory, "test-export-key.p12");
	credentialManager.exportKeyPair(alias, fileToExportTo.toPath(), privateKeyAndPKCS12KeystorePassword);
	assertTrue(fileToExportTo.exists());
	// Load it back from the file we just saved
	KeyStore ks = credentialManager.loadPKCS12Keystore(fileToExportTo.toPath(), privateKeyAndPKCS12KeystorePassword);
	Enumeration<String> aliases = ks.aliases();
	Key newPrivateKey = null;
	Certificate[] newPrivateKeyCerts = null;
	while (aliases.hasMoreElements()) {
		// The test-private-key-cert.p12 file contains only one private key
		// and corresponding certificate entry
		alias = aliases.nextElement();
		if (ks.isKeyEntry(alias)) { // is it a (private) key entry?
			newPrivateKey = ks.getKey(alias,
					privateKeyAndPKCS12KeystorePassword.toCharArray());
			newPrivateKeyCerts = ks.getCertificateChain(alias);
			break;
		}
	}
	assertNotNull(newPrivateKey);
	assertNotNull(newPrivateKeyCerts);
	//assertTrue(Arrays.equals(newPrivateKey.getEncoded(), privateKey.getEncoded()));
	assertTrue(newPrivateKey.equals(privateKey));
	assertTrue(Arrays.equals(newPrivateKeyCerts, privateKeyCertChain));
}