i want to implement SHA 1 Algorithm using java. Can any one help me
-
codase.com/search/…Amarghosh– Amarghosh2010-05-10 05:05:55 +00:00Commented May 10, 2010 at 5:05
-
Do you want to implement it from scratch or you want to call it from some library?vodkhang– vodkhang2010-05-10 05:06:46 +00:00Commented May 10, 2010 at 5:06
-
4Why? 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.Dean Harding– Dean Harding2010-05-10 05:14:18 +00:00Commented May 10, 2010 at 5:14
-
Maybe it's homework or just plain interest.fish– fish2010-05-10 06:14:29 +00:00Commented 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.MonkeyWrench– MonkeyWrench2011-01-25 14:44:44 +00:00Commented Jan 25, 2011 at 14:44
Add a comment
|
3 Answers
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...?
Comments
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
Victor Axelsson
I think you forgot the () on the
getBytes() function.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
James Newman
It's possible that the want to implement it in order to understand how it works, without wanting to use it in production.