Jump to content
Sign in to follow this  
Musicmasta

Cryptography Any Java Program

Recommended Posts

This will work for any java program, you can use the following code to create a hash using any of the following cryptographic hash functions:
MD2
MD5
Sha1
Sha-256
Sha-384
Sha-512

[code]
import java.security.*;


public static String createHash(String s) {
try {
MessageDigest md = MessageDigest.getInstance("Sha-512");//Change this to whatever Hash function you want to
byte[] array = md.digest(s.getBytes());
StringBuffer sb = new StringBuffer();
for (int i = 0; i < array.length; i++) {
sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3));
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
}
return null;
}
[/code]

There you go, secure hash for any string you want. Personally I use it to create a hash for the data I store on my MySQL Database, but there's multiple uses.

Share this post


Link to post
Share on other sites
This isn't even your work.

[url]http://m2tec.be/blog/2010/02/03/java-md5-hex-0093[/url]

Share this post


Link to post
Share on other sites
[quote name='Stacx']This isn't even your work.

[url]http://m2tec.be/blog/2010/02/03/java-md5-hex-0093[/url][/QUOTE]

He never said it was nor gave credits to himself. It's a snippet people can find useful. Either way, thanks music.

Share this post


Link to post
Share on other sites
[quote name='Citellum']He never said it was nor gave credits to himself. It's a snippet people can find useful. Either way, thanks music.[/QUOTE]

The common standard is to credit whoever is the original author of (anything), no? You should hop the fuck off you absolute waste of space lol. Edited by Stacx

Share this post


Link to post
Share on other sites
[quote name='Stacx']The common standard is to credit whoever is the original author of (anything), no? You should hop the fuck off you absolute waste of space lol.[/QUOTE]

To be fair, the only thing in that entire method that can possibly be credited to another person is
[code]
(array[i] & 0xFF) |0x100).substring(1,3));
[/code]
The rest of the code is simply using the Message Digest class which is included in the default java library, which you don't really give credit for. Seeing as I informed of additional constructions of the message digest class supported by this code, which weren't provided by the link you posted, it is useful information. Also, I didn't receive my code from whatever link that is and the equation used is floating all over the internet. There's only 14 lines of code there, out of those 14 lines anybody with a simple understanding of java could write 13 of them. So how about you
[quote name='Stacx']hop the fuck off you absolute waste of space lol.[/QUOTE] Edited by Musicmasta

Share this post


Link to post
Share on other sites
[quote name='Stacx']The common standard is to credit whoever is the original author of (anything), no? You should hop the fuck off you absolute waste of space lol.[/QUOTE]

Oh, that's why this community died.

Share this post


Link to post
Share on other sites
[quote name='titandino']Oh, that's why this community died.[/QUOTE]

What does this little thing with me and Citellum have to do with the community as one, and moreover who are you to talk about this community,,, Apologies for the OP!

Share this post


Link to post
Share on other sites
[quote name='Stacx']What does this little thing with me and Citellum have to do with the community as one, and moreover who are you to talk about this community,,, Apologies for the OP![/QUOTE]

<3 you too bby

Share this post


Link to post
Share on other sites
Sign in to follow this  

×