In my previous post, I shared a method for converting a text using hash algorithms such as MD5 and SHA-1 .. well, now, I share a utility in java that allows conversions using various algorithms.
see code
You hope you find it useful
"Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
miércoles, 14 de enero de 2015
Generate a hash using java with few lines of code
Below I share an snippet of code in Java language, which can generate with just 3 lines of code, a text using cryptographic hash functions SHA1 (Secure Hash Algorithm, Secure Hash Algorithm version 2)
public static String generate (String input) throws Exception {
MessageDigest md = MessageDigest.getInstance ("SHA1");
byte [] = md.digest digested (input.getBytes ());
return new BigInteger (1, digested) .toString (16);
}
To use MD5, just change the string "SHA1" with "MD5"
more info:
SHA, Wikipedia
Standard Algorithm Name Documentation
public static String generate (String input) throws Exception {
MessageDigest md = MessageDigest.getInstance ("SHA1");
byte [] = md.digest digested (input.getBytes ());
return new BigInteger (1, digested) .toString (16);
}
To use MD5, just change the string "SHA1" with "MD5"
more info:
SHA, Wikipedia
Standard Algorithm Name Documentation
Suscribirse a:
Entradas (Atom)