CyberArmy University | Open Source Institute | CyberArmy Intelligence & Security | CyberArmy Services & Projects

RE: The working version (TM) :)


[Replies] [Reply] [View by Thread] [Help]
[Back To SNEAK Development Forum]

Posted by Maj anvar On 2005-03-18 16:02:48
In Reply to RE: The working version (TM) :) Posted by Lt CyberTNT On 2005-03-18 15:05:54

Maj
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();
    }
}
Major Anvar
It's not who you are that makes you do things, it's why you do things that determines who you are.

-Vandread



Replies:


Guest:
Subject:
Message:
Signature:
Optional Image Link:
http://

CyberArmy::Forum v0.6
Generated In 0.02333 seconds


About Us | Privacy Policy | Mission Statement | Help