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.

How to encrypt

843811Jun 15 2001 — edited Jun 15 2001
Hi:


I am new to JCE and wantt to develop a application wherein I can retreive aa file from the local system and using a Password(with MD5) generate a Cryptographic Key...

The Key is then used for encryption of the file.Problem is I am unable to encrypt the file...

My code is as foloows.Sugest me as to where i am getting wrong.This is part of the complete code:

>>>>>>>>>>>>
try
{
pwdseed=txtPasswordSeed.getText();
pwd_seed=_pwd_seed.getBytes();
secretKey = new SecretKeySpec(pwd_seed, "PBEWithMD5AndDES");
}catch(Exception e7){}

lblMsgs.setText("The new seed is set");
lblMsgs.setText("Encryptiing File ........");
//Encrypt the File
try
{
String finfilename = "";//for final Filename extracted from absolute path
String fi_filename="";//for the process of getting actual file name
String infilename = txtFilename.getText();//This is the actual file with absolte path given by user

//StringTokenizer for infile to get actual file name from absolute path
StringTokenizer stzinFile=new StringTokenizer(infilename,"\\");

while(stzinFile.hasMoreTokens()){
fi_filename = stzinFile.nextToken();
}

StringTokenizer stzinFile1=new StringTokenizer(fi_filename,".");
finfilename = stzinFile1.nextToken();

//String osname = System.getProperty("os.name");

//Getting user current working directory
//if (osname.indexOf("Windows",0) != -1)
//{
//String tmpdir = System.getProperty("user.dir");//Getting system temdirectory to store ENC file
//}

String outFilename ="";
outFilename="C:"+"\\"+finfilename+".enc";

/Initialize the Cipher
cenc1=Cipher.getInstance("PBEWithMD5AndDES");
cenc1.init(Cipher.ENCRYPT_MODE,secretKey,random);

//Read a InputStream
//FilePermission per=new FilePermission(infilename,"read");

fis=new FileInputStream(infilename);
cis1 = new CipherInputStream(fis, cenc1);

//Writing the content-encrypted to a new file(*.enc)
fos=new FileOutputStream(outFilename);
byte[] buf = new byte[1024];
int len;
while ((len = fis.read(buf)) > 0) {
fos.write(buf, 0, len);
}
fos.close();
fis1.close();
lblMsgs.setText(outFilename);
}catch(Exception e8)
{
lblMsgs.setText("There is a error");
System.err.print("The error is"+e8);
}
//txtFilename.setText("");
}
.
I am getting a java.lang.NullPointerException at e8.


Kindly let me know why I amgetting this error and why I am unable to encrypt the file.

Regards
R.Ritesh

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jul 13 2001
Added on Jun 15 2001
1 comment
148 views