aspose file tools*
The moose likes Beginning Java and the fly likes Very Important Question plz Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Very Important Question plz" Watch "Very Important Question plz" New topic
Author

Very Important Question plz

Mohammad Ahmad
Greenhorn

Joined: Mar 21, 2006
Posts: 18
iam trying to implement SHA1 (Secure Hash Algorithm) in java ..and i do face this problem so plz help me on :
in thie algorithm i have a message that i want to calculate the hash for ...the message length must be multiple of 512 to deal with it..so i first calculate the message length in bits for example say it was 1850 bit..then i calculated the number of needed padding bits to have the message with the desired length and it was :
170 "0" bit
1 "1" bit
how can i pad this bits to my message??
how could i get the 170 "0" bit or 1 "1" bit?
then i must convert the length of my messge which as we said above 1850 to 64-bit unsigned integer and also pad it to my message to have finally the desired length..do i have to deal with this numbers in binary or ASCII or how can i do that???plz reply to me very important..
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

I am assuming this is a homework question, since the SHA1 algorithm is part of the Java core packages.

how can i pad this bits to my message??
how could i get the 170 "0" bit or 1 "1" bit?


What techniques have you learn recently in class? Did you learn shifting yet (>> and << ) ? Did you learn the bitwise operators yet (& and |) ?

These last two questions are obviously hints...

Henry
[ March 23, 2006: Message edited by: Henry Wong ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Mohammad Ahmad
Greenhorn

Joined: Mar 21, 2006
Posts: 18
hi Henry thanx a lot...but this is not a homework it self iam working with a project a small part of it is using SHA1 but what u mean it is from the java core package u mean i dont need to implement it does it exist???iam very new to java so i read about shifting and bitwise but plz explain to me more what does this means to me here?plz reply in a clear way..
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Take a look at the java.security.MessageDigest class. It will generate you the checksums based on a whole bunch of standards -- and SHA1 is one of the supported standards.

You can probably also google for a quick example on how to use it.

Henry
 
 
subject: Very Important Question plz