PDA

Click to See Complete Forum and Search --> : KeyStore


Dillinger4
Feb 20th, 2001, 08:36 PM
Hi all!
If anyone is fimiliar with the JCE and the java.Security package and could give me a hand, it would be greaty
appreciated.

I have a program which Encrypts and Decrypts files using DES (Data Encryption Standard)...... my program
works great. I specify from the DOS command line what
file i would like to encrypt and it encrypts it... But when i try to Decrypt the same file a InvalidKeyException is thrown.

Im trying to code a KeyStore to hold the keys so Decryption is possible. but it is a bit confusing... any
help or suggestions would be cool..

according to certain books they say "Once you have created a KeyStore, use load() to read it's contents from a stream." so am i using load to read passwords from a file???


/*
if a password is specified for file encryption and it does not exist in the key store it is created and saved. If it does it is retrieved for use
*/
import java.security.KeyStore;
import java.io.*;

public class keyVault{
public static void main(String[] args){

keyvault(password);
}
public static void keyvault(String password){

try {

FileInputStream fin = new FileInputStream("C:\\passwords.txt");
KeyStore keyvault = KeyStore.getInstance("JCEKS","SunJCE");

byte[] buffer = new byte[100];
char[] passwordhold = new char[1000];

while(true){
int bytesread = fin.read(buffer);
if(bytesread == -1) break;
}

passwordhold = (char[]) buffer.clone();
keyvault.load(password);

}catch(Exception e){System.err.println(e);}

} //end method
} // end class