RE: The working version (TM) :) |
||
![]() Maj anvar Ok, corrected version below: package net.cyberarmy.sneak.scheme;
import net.cyberarmy.sneak.Scheme;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Scheme implements Scheme {
public String getNameKey() {
return "scheme.MD5.name";
}
public String getDescriptionKey() {
return "scheme.MD5.description";
}
/**
* Default method to run this.
* @param input String -- The string we want to MD5.
* @return String -- The result we get.
*/
public String execute(String input) {
if (input == null) return null;
MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
}
// Eat the exception because it shouldn't happen.
catch (NoSuchAlgorithmException nse) {
return "Source-code Error";
}
// Get the array of bytes representing the MD5 hash.
byte[] bytes = md.digest(input.getBytes());
StringBuffer md5 = new StringBuffer();
// Loop through the array to get all the bytes, convert
// them to hex, and add them to our string.
for (int i = 0; i < 16; i++) {
md5.append(String.format("%02x", bytes[i]));
}
return md5.toString();
}
}
It's not who you are that makes you do things, it's why you do things that determines who you are. Replies:
|
||
| CyberArmy::Forum v0.6 Generated In 0.02333 seconds |