0

i want to implement SHA 1 Algorithm using java. Can any one help me


Refer this

5
  • codase.com/search/… Commented May 10, 2010 at 5:05
  • Do you want to implement it from scratch or you want to call it from some library? Commented May 10, 2010 at 5:06
  • 4
    Why? A hand-rolled version is almost certain to be less secure and have more bugs than a version that has been implemented by security professionals and reviewed many times by other security professionals. Commented May 10, 2010 at 5:14
  • Maybe it's homework or just plain interest. Commented May 10, 2010 at 6:14
  • There's plenty of code snippets that can be easily found with a simple web search. If you have more specific questions or concerns, please add them when submitting your question. Commented Jan 25, 2011 at 14:44

3 Answers 3

2

Not sure quite what you're asking; Wikipedia has pseudo-code: http://en.wikipedia.org/wiki/SHA-1 you should be able to code it up in java from that relativly easily... Did you have any specific question about doing it, or...?

Sign up to request clarification or add additional context in comments.

Comments

1

I think you can just use java.security.MessageDigest. For ASCII data this is as simple as

String src = ...
MessageDigest md = MessageDigest.getInstance("SHA-1");
String sha1 = new String(md.digest(src.getBytes()));

1 Comment

I think you forgot the () on the getBytes() function.
0

Just don't do it, load the bouncycastle libraries and use them. Or look at their source, and then you know one way how to implement it :).

1 Comment

It's possible that the want to implement it in order to understand how it works, without wanting to use it in production.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.