1

I am trying to read secret key (passphrase) from JCEKS keystore using Java code , code is working for JKS keystore but not for JCEKS keystore. i am using ibm_sdk71 as runtime (due to project requirements).

public static String getPasswordFromKeystore(String entry, String keystoreLocation, String keyStorePassword,String keyPP1) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, InvalidKeySpecException, java.security.UnrecoverableEntryException{
    char[] password = "new".toCharArray() ;  
    FileInputStream fIn = new FileInputStream(keystoreLocation);
    KeyStore.PasswordProtection keyStorePP = new KeyStore.PasswordProtection(keyStorePassword.toCharArray());
    KeyStore.PasswordProtection keyPP = new KeyStore.PasswordProtection(keyPP1.toCharArray());
    KeyStore ks= KeyStore.getInstance("JCEKS");
    ks.load(fIn, keyStorePassword.toCharArray());
    SecretKeyFactory factory = SecretKeyFactory.getInstance("PBE");
    KeyStore.SecretKeyEntry ske;
    ske = (KeyStore.SecretKeyEntry)ks.getEntry(entry, keyPP);
    PBEKeySpec keySpec;
    keySpec = (PBEKeySpec)factory.getKeySpec(ske.getSecretKey(),PBEKeySpec.class);
    password = keySpec.getPassword();
  return new String(password);
}

Appreciate any guidance. Regards

niting
  • 55
  • 4
  • 12
  • Can you try this solution please: https://stackoverflow.com/questions/38744181/export-secret-key-from-jck-key-store – marme1ad Sep 23 '18 at 05:58
  • Figured out , as i am using IBMJDK , PBE is replaced with PBEWithMD5AndDES in below code SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEWITHMD5ANDDES"); but now i am stuck while getting keySpecification as i am using PBEkeySpec.class – niting Sep 25 '18 at 05:53

0 Answers0