v3CertGen.setSubjectDN(new X509Principal("CN=" + hostname + ", OU=None, O=None L=None, C=None"));
v3CertGen.setPublicKey(KPair.getPublic());
v3CertGen.setSignatureAlgorithm("MD5WithRSAEncryption");
X509Certificate PKCertificate = v3CertGen.generateX509Certificate(KPair.getPrivate());
// store the certificate containing the public key,this file is needed
// to import the public key in other key store.
File certFile = new File(keyStoreFile.getParentFile(),hostname+".cert");
FileOutputStream fos = new FileOutputStream(certFile.getAbsoluteFile());