@SneakyThrows public void addKeyToKeystore(KeyStore keyStore,X509Certificate cert,RSAPrivateKey privateKey,String alias,String password){
  KeyStore.PasswordProtection pass=new KeyStore.PasswordProtection(password.toCharArray());
  Certificate[] certificateChain={cert};
  keyStore.setEntry(alias,new KeyStore.PrivateKeyEntry(privateKey,certificateChain),pass);
}

@ SneakyThrows public void addKeyToKeystore ( KeyStore keyStore , X509Certificate cert , RSAPrivateKey privateKey , String alias , String password ) { KeyStore . PasswordProtection pass = new KeyStore . PasswordProtection ( password . toCharArray ( ) ) ; Certificate [ ] certificateChain = { cert } ; keyStore . setEntry ( alias , new KeyStore . PrivateKeyEntry ( privateKey , certificateChain ) , pass ) ; }
based on a public certificate , private key , alias and password , this method will load the certificate and private key as an entry into the keystore , and it will set the provided alias and password to the keystore entry .
