aspose file tools*
The moose likes Beginning Java and the fly likes Problem in Files (plz help me in???) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem in Files (plz help me in???)" Watch "Problem in Files (plz help me in???)" New topic
Author

Problem in Files (plz help me in???)

Mohammad Ahmad
Greenhorn

Joined: Mar 21, 2006
Posts: 18
Hi,plz i havwe aproblem in files:
i had implemented the Secure Hash Algorithm SHA1 in java ,the input to my program must be the message that i want to calculate the Digest for so it must be stored in a file ,and the output also(the Digest) mustbe stored in other file but the problem is:
when i pass the input file to my program (which contains the message) each time iy gives me the same output ,although when i pass it any string(without being saved in a file) it gives me each time a different and right hash value so where is the problem in the input file???
the second problem also is in the output file ,that is the outpot of my file must be 20 character(160 bit) but when i write it to an output file it gives me only 19 characters or gives me something like this if my message is too long |||||||||| ,although also it prints it below on the Jbuilder compiling and run area in the right way i mean it pints 20 caharctes even the length of my mesage was long but the problem appears when i write it to a file!!!
so plz what the problem could be in both the input/output ile???
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14139
    
  18

Your question is confusing and it's not really clear what's wrong - it will be difficult to give you a precise answer to what's wrong in your application.

Did you write your own implementation of the SHA algorithm or did you use the implementation that's available in the JDK (see the API docs of java.util.MessageDigest, for example)?

Post some code, describe exactly the input of your program and the output, and why the output is different from what you expect.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Mohammad Ahmad
Greenhorn

Joined: Mar 21, 2006
Posts: 18
no i have implemented it from my own not by using what is available in the JDK ...the problem is as following:
**the input of my program is the message string which i need to calculate the digest for...
**the output of my program is the Digest
now the output(Digest) must be 160 bit(20 characters)the problem is with using files :
i defined two files one to store my input message the other is for holding the output(Digest) and i have problem in both these files:
for the input file which i put in it the message string when i pass this file name to my program to read the message it gives me every time the same digest even if i change the content of this file in other word i changed the message it self...but if i pass to my program the message string it self not the file name which contains the message it gives mr=e the right answer:

System.out.println ("The Program is Reading Your input Message to calculate the Digest");
try{
FileInputStream Message_File=new FileInputStream ("C:/JBuilder4/lib/input.txt");
BufferedReader buff=new BufferedReader(new InputStreamReader(Message_File));

System.out.println("The resulted Digest in base64 form for the Input_Message =" +Base64_SHA1_Encoding("Message_File"));-->it gives here same digest to all strings

the second problem is with the output file:
when i print the result on the screen using JBuilder it gives me the right result which it is digest of 20 characters but when i want wrote it into a file and i opened the file i find only 19 characters not 20 and if my message was long it gives me something like this |||||||
so for example when i print the result i got this digest:
�#?.?�?Y2??Y2?? ?- but when i open the file i see only 19 charactes there is a missing symbol or i see if the message is longno i have implemented it from my own not by using what is available in the JDK ...the problem is as following:
**the input of my program is the message string which i need to calculate the digest for...
**the output of my program is the Digest
now the output(Digest) must be 160 bit(20 characters)the problem is with using files :
i defined two files one to store my input message the other is for holding the output(Digest) and i have problem in both these files:
for the input file which i put in it the message string when i pass this file name to my program to read the message it gives me every time the same digest even if i change the content of this file in other word i changed the message it self...but if i pass to my program the message string it self not the file name which contains the message it gives mr=e the right answer:

System.out.println ("The Program is Reading Your input Message to calculate the Digest");
try{
FileInputStream Message_File=new FileInputStream ("C:/JBuilder4/lib/input.txt");
BufferedReader buff=new BufferedReader(new InputStreamReader(Message_File));

System.out.println("The resulted Digest in base64 form for the Input_Message =" +Base64_SHA1_Encoding("Message_File"));-->it gives here same digest to all strings

the second problem is with the output file:
when i print the result on the screen using JBuilder it gives me the right result which it is digest of 20 characters but when i want wrote it into a file and i opened the file i find only 19 characters not 20 and if my message was long it gives me something like this |||||||
so for example when i print the result i got this digest:
�#?.?�?Y2??Y2?? ?- but when i open the file i see only 19 charactes there is a missing symbol or i see if the message is long ||||||||
so where the problem may be???i need a serious help plz...
--------------------------------------------------------------------------------

so where the problem may be???i need a serious help plz...
--------------------------------------------------------------------------------

EDIT by mw: Added additional info posted as separate topic.
[ April 27, 2006: Message edited by: marc weber ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in Files (plz help me in???)