Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encypted file contents to String

Status
Not open for further replies.

joew888

Programmer
Apr 2, 2003
1
ZA
Hi,
I have a file that has been encrypted (using bouncycastle for RSA encyption) but I now need to read from the file and get a String from it. I have used FileReader and Stringwriter to do so. The problem I have is that the FileReader.read() method is returning 65533 for a certain part of the file. But the StringWriter.write(int c) method seems to be writing with the value of 236 instead of the 65533. I have also tried using a FileInputStream instead of the file reader but to no avail. I suspect the problem is when the StringWriter writes the 65533 it gets converted due to the fact that the 16 high-order bits are ignored by the Writer class. I find this very strange as surely the 16 low order bits results in 65535 ((2^16)-1) which although very close to the 65533 is still higher than it. Is there a different class I could use to get the contents converted to a String? Below is a snippet of my code (using the FileInputStream):

FileInputStream inFile=new FileInputStream(filename);
StringWriter sw = new StringWriter();
int bit=0;
while ((bit = inFile.read())>=0){
sw.write(bit);
sw.flush();
}
return sw.toString();

Is it possible that the StringWriter.toString() method is actually the problem here?

Thanks,
Joe

 
If the file is encrypted aren’t the contents binary and therefore you must read the contents using a binary read method then decrypt the contents before you can get the String data from the file?


-pete
I just can't seem to get back my IntelliSense
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top