dcsimg
Problems reading a file when running code in unix
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   bd_msh
Posted On:   Tuesday, June 29, 2004 09:59 AM

Hi, Can someone please look at this code and tell me wut am doing wrong. I ran the same code in windows and it works fine. Then when i change the path to read the file in unix. It gives me an error Could not read the private key from jail/usr/jakarta-tomcat-4.1.30/webapps/webappName/WEB-INF/classes/com/proj/servlets/code_private.key There is something wrong in how am giving the path to read the file The file i am trying to read is under here in unix environment. jail/usr/jakarta-tomcat-4.1.30/webapps/webappsName/WEB- INF/classes/com/proj/servlets/ As am getting this error only when am running in unix and not in windows, am pretty sure that am doing somthing wrong when setting the   More>>

Hi,
Can someone please look at this code and tell me wut am doing wrong. I ran the same code in windows and it works fine. Then when i change the path to read the file in unix. It gives me an error


Could not read the private key from jail/usr/jakarta-tomcat-4.1.30/webapps/webappName/WEB-INF/classes/com/proj/servlets/code_private.key


There is something wrong in how am giving the path to read the file
The file i am trying to read is under here in unix environment.
jail/usr/jakarta-tomcat-4.1.30/webapps/webappsName/WEB- INF/classes/com/proj/servlets/


As am getting this error only when am running in unix and not in windows, am pretty sure that am doing somthing wrong when setting the path in variable keyFileLocation.
Please look at it and let me know what am doing wrong.
Thanks in advance





package com.proj.servlets;



import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;



public class Keys
{



private String keyFileLocation = null;
private String publicKeyFile = null;
private String privateKeyFile = null;



public Keys()
{



// replace the keyFileLocation with the location where the public and private key files have
// been saved



keyFileLocation = "jail/usr/jakarta-tomcat-4.1.30/webapps/webappsName/WEB- INF/classes/com/proj/servlets/";



publicKeyFile= "public.key";
privateKeyFile= "private.key";
}



public PublicKey getPublicKey(String client)
{


String publicKeyLocation = null;



try {
publicKeyLocation = keyFileLocation + client + "_" + publicKeyFile;

System.out.println("ReadingPublicKey: " + publicKeyLocation);


ObjectInputStream in = new ObjectInputStream(new FileInputStream(publicKeyLocation));


PublicKey pubKey = (PublicKey)in.readObject();
in.close();


return pubKey;


} catch (Exception e) {


System.out.println("Could not read the public key from " + publicKeyLocation);


return null;
}


}


public PrivateKey getPrivateKey(String client)
{
String privateKeyLocation = null;


try {


privateKeyLocation = keyFileLocation + client + "_" + privateKeyFile;


System.out.println("ReadingprivateKeyLocation: " + privateKeyLocation);


ObjectInputStream in = new ObjectInputStream(new FileInputStream(privateKeyLocation));


PrivateKey privKey = (PrivateKey)in.readObject();
in.close();


return privKey;


} catch (Exception e) {


System.out.println("Could not read the private key from " + privateKeyLocation);


return null;
}


}
}

   <<Less

Re: Problems reading a file when running code in unix

Posted By:   Christopher_Koenigsberg  
Posted On:   Tuesday, June 29, 2004 02:10 PM

just a hunch -- should that be "jail/" or should it really be "/jail/"?
About | Sitemap | Contact