The example below demonstrates how to change the password of a private key that has been imported in a KeyStore file.
We should know either the User Id of the key or the key Id; this example uses the method that accepts User Id.
import com.didisoft.pgp.KeyStore;
public class ChangePrivateKeyPassword {
public static void main(String[] args) throws Exception{
// initialize the KeyStore instance
KeyStore ks = new KeyStore("pgp.keystore", "changeit");
// change secret key password
String keyUserId = "test@gmail.com";
String oldPassword = "changeit";
String newPassword = "new_private_key_password";
ks.changePrivateKeyPassword(keyUserId, oldPassword, newPassword);
}
}
Eventually we can export it lately if we prefer to keep it in a standalone file.