J
jimgardener
hi
i created a keystore as below
public static void makeKeyStore(){
try{
KeyStore ks=KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null,"".toCharArray());
FileOutputStream ksout=new FileOutputStream("myks.keystore");
char[] password = new char[] {'m','y','n','a','m','e'};
ks.store(ksout, password);
Arrays. fill(password, '\u0000' ) ;
}
catch(Exception e){
e.printStackTrace();
}
}
then i tried to store a generated key using an alias
public static void putEntriestoKS(){
try{
KeyStore ks=KeyStore.getInstance(KeyStore.getDefaultType());;
FileInputStream fin=new FileInputStream("myks.keystore");
char[] password = new char[] {'m','y','n','a','m','e'};
ks.load(fin,password);
FileOutputStream fout=new FileOutputStream("myks.keystore");
KeyGenerator kg=KeyGenerator.getInstance("AES");
SecretKey skey=kg.generateKey();
ks.setKeyEntry("mysecretkey", skey, password,null);
ks.store(fout,password);
Arrays.fill(password,'\u0000');
}
catch(Exception e){
e.printStackTrace();
}
}
when i run this i am getting a java.security.KeyStoreException: Cannot
store non-PrivateKeys
How then can i store SecretKey ?Do i have to use another provider?can
someone explain?
thanks
Jim
i created a keystore as below
public static void makeKeyStore(){
try{
KeyStore ks=KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null,"".toCharArray());
FileOutputStream ksout=new FileOutputStream("myks.keystore");
char[] password = new char[] {'m','y','n','a','m','e'};
ks.store(ksout, password);
Arrays. fill(password, '\u0000' ) ;
}
catch(Exception e){
e.printStackTrace();
}
}
then i tried to store a generated key using an alias
public static void putEntriestoKS(){
try{
KeyStore ks=KeyStore.getInstance(KeyStore.getDefaultType());;
FileInputStream fin=new FileInputStream("myks.keystore");
char[] password = new char[] {'m','y','n','a','m','e'};
ks.load(fin,password);
FileOutputStream fout=new FileOutputStream("myks.keystore");
KeyGenerator kg=KeyGenerator.getInstance("AES");
SecretKey skey=kg.generateKey();
ks.setKeyEntry("mysecretkey", skey, password,null);
ks.store(fout,password);
Arrays.fill(password,'\u0000');
}
catch(Exception e){
e.printStackTrace();
}
}
when i run this i am getting a java.security.KeyStoreException: Cannot
store non-PrivateKeys
How then can i store SecretKey ?Do i have to use another provider?can
someone explain?
thanks
Jim