class CredentialManagerImpl implements CredentialManager,
		Observable<KeystoreChangedEvent> {

	@Override
	public void exportKeyPair(String alias, Path exportFile,
			String pkcs12Password) throws CMException {
		// Need to make sure we are initialized before we do anything else
		// as Credential Manager can be created but not initialized
		initialize();

		synchronized (keystore) {
			// Export the key pair
			try {
				// Get the private key for the alias
				PrivateKey privateKey = (PrivateKey) keystore.getKey(alias,
						masterPassword.toCharArray());

				// Get the related public key's certificate chain
				Certificate[] certChain = getKeyPairsCertificateChain(alias);

				// Create a new PKCS #12 keystore
				KeyStore newPkcs12 = KeyStore.getInstance("PKCS12", "BC");
				newPkcs12.load(null, null);

				// Place the private key and certificate chain into the PKCS #12
				// keystore. Construct a new alias as
				// "<SUBJECT_COMMON_NAME>'s <ISSUER_ORGANISATION> ID"

				String sDN = ((X509Certificate) certChain[0])
						.getSubjectX500Principal().getName(RFC2253);
                                
                                ParsedDistinguishedName parsedDN = dnParser.parseDN(sDN);
				String sCN = parsedDN.getCN();

				String iDN = ((X509Certificate) certChain[0])
						.getIssuerX500Principal().getName(RFC2253);
                                parsedDN = dnParser.parseDN(iDN);
				String iCN = parsedDN.getCN();

				String pkcs12Alias = sCN + "'s " + iCN + " ID";
				newPkcs12.setKeyEntry(pkcs12Alias, privateKey, new char[0],
						certChain);

				// Store the new PKCS #12 keystore on the disk
				try (OutputStream fos = Files.newOutputStream(exportFile)) {
					newPkcs12.store(fos, pkcs12Password.toCharArray());
				}
			} catch (Exception ex) {
				String exMessage = "Failed to export the key pair from the Keystore";
				logger.error(exMessage, ex);
				throw new CMException(exMessage, ex);
			}
		}
	}

	public  CredentialManagerImpl();

}