1 //Copyright (C) 2004, Brian Enigma <enigma at netninja.com>
2 //This file is part of MagicCodes.
3 //
4 //MagicCodes is free software; you can redistribute it and/or modify
5 //it under the terms of the GNU General Public License as published by
6 //the Free Software Foundation; either version 2 of the License, or
7 //(at your option) any later version.
8 //
9 //MagicCodes is distributed in the hope that it will be useful,
10 //but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 //GNU General Public License for more details.
13 //
14 //You should have received a copy of the GNU General Public License
15 //along with Foobar; if not, write to the Free Software
16 //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 package org.ninjasoft.magiccodes.plugins;
18
19 import java.security.MessageDigest;
20 import java.security.NoSuchAlgorithmException;
21
22 /***
23 * Plugin for turning something into an MD5 hash
24 * @author enigma
25 */
26 public class Md5 implements Plugin {
27 public String getName() {
28 return "MD5";
29 }
30 public String getDescription() {
31 return "Hashes the input to MD5";
32 }
33 public boolean usesKey() {
34 return false;
35 }
36 public boolean isInformational() {
37 return false;
38 }
39 public int[] doAction(int[] in, int[] key) {
40 byte[] inData = new byte[in.length];
41 for (int i=0; i<in.length; i++)
42 inData[i] = (byte) in[i];
43 try {
44 StringBuffer md5hash = new StringBuffer("");
45 MessageDigest mDigest = MessageDigest.getInstance("MD5");
46 int byteCounter, tmpValue;
47 Byte tmpByte;
48
49 // Create the MD5 hash.
50 mDigest.update(inData);
51 byte[] mdBytes = mDigest.digest();
52 int[] result = new int[mdBytes.length];
53 for (int i=0; i<mdBytes.length; i++)
54 result[i] = (mdBytes[i] + 256) % 256;
55 return result;
56 } catch(NoSuchAlgorithmException e) {
57 e.printStackTrace();
58 // Return null on failure.
59 return null;
60 }
61 }
62 }
This page was automatically generated by Maven