1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
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
59 return null;
60 }
61 }
62 }