package co.com.dendritas.KleyberTool; import android.content.Context; import android.util.Log; import com.google.appinventor.components.annotations.*; import com.google.appinventor.components.runtime.*; import com.google.appinventor.components.common.ComponentCategory; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @DesignerComponent(version = 1, description = "", category = ComponentCategory.EXTENSION, nonVisible = true, iconName = "") @SimpleObject(external = true) public class KleyberTool extends AndroidNonvisibleComponent implements Component { public static final int VERSION = 1; private ComponentContainer container; private Context context; private static final String LOG_TAG = ""; public KleyberTool(ComponentContainer container) { super(container.$form()); this.container = container; context = (Context) container.$context(); Log.d(LOG_TAG, "KleyberTool" ); } @SimpleFunction(description = "") public String EncodeMD5(String text){ return MD5.encrypt(text); } public static final class MD5 { /** * Encrypt a text into MD5 * @param text * @return MD5 encrypted text */ public final static String encrypt(final String text) { try { // Create MD5 Hash MessageDigest digest = MessageDigest .getInstance("MD5"); digest.update(text.getBytes()); byte messageDigest[] = digest.digest(); // Create Hex String StringBuffer hexString = new StringBuffer(); for (int i = 0; i < messageDigest.length; i++) { String h = Integer.toHexString(0xFF & messageDigest[i]); while (h.length() < 2) h = "0" + h; hexString.append(h); } return hexString.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; } } }