Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

NEED HELP!!! converting jceks to jks

843811Mar 12 2003 — edited Mar 16 2003
Hi all,

I need help in converting a keystore from jceks to jks. I wrote a program that opens both keystore files, reads the keys from the jceks keystore and writes to jks keystore. The initial jks keystore is empty. The program executes fine, but when I use the keytool to read the new keystore I get the following:

c:\keytool -list -keystore jkskeystore.dat
Enter keystore password: something

Keystore type: jks
Keystore provider: SUN

Your keystore contains 1 entry

some.key, Mar 12, 2003, keyEntry,
keytool error: java.lang.ArrayIndexOutOfBoundsException: 0

Any ideas on this? Are there tools out there that will do the conversion?

Any help is apreciated!!!

This is the program:

import java.io.*;
import java.security.*;

import javax.crypto.*;

public class KeyStoreTypeTransfer{

private static final String OLD_KEYSTORE = "keystore.dat";
private static final String NEW_KEYSTORE = "jkskeystore.dat";

private static final String OLD_PASSWORD = "something";
private static final String NEW_PASSWORD = "something";

private static final String OLD_ALIAS = "some.key";
private static final String NEW_ALIAS = "some.key";

public static void main(String[] args){

try {
// get the original keystore

KeyStore keyStore = KeyStore.getInstance("JCEKS");
KeyStore keyStoreJKS = KeyStore.getInstance("JKS","SUN");

InputStream inputStream = new FileInputStream(OLD_KEYSTORE);
InputStream inputStreamJKS = new FileInputStream(NEW_KEYSTORE);

keyStore.load(inputStream, OLD_PASSWORD.toCharArray());
keyStoreJKS.load(inputStreamJKS, NEW_PASSWORD.toCharArray());

SecretKey secretKey = (SecretKey) keyStore.getKey(OLD_ALIAS, OLD_PASSWORD.toCharArray());
System.out.println(secretKey.getFormat() + " " + secretKey.getAlgorithm());

keyStoreJKS.setKeyEntry(NEW_ALIAS, secretKey, NEW_PASSWORD.toCharArray(), null);


keyStoreJKS.store(new FileOutputStream(NEW_KEYSTORE), NEW_PASSWORD.toCharArray());
}
catch (Exception e){
e.printStackTrace();
}

return;
}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 13 2003
Added on Mar 12 2003
1 comment
2,029 views