Android Open Source - LTM M D5 Sum






From Project

Back to project page LTM.

License

The source code is released under:

Apache License

If you think the Android project LTM listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/* (C) 2012 Pragmatic Software
   This Source Code Form is subject to the terms of the Mozilla Public
   License, v. 2.0. If a copy of the MPL was not distributed with this
   file, You can obtain one at http://mozilla.org/MPL/2.0/
 *//* w w w .j  a v  a2s.  c  o  m*/

package com.chrisplus.ltm.utils;

import android.util.Log;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.math.BigInteger;

public class MD5Sum {
    private static MessageDigest md;
    private final static String TAG = MD5Sum.class.getSimpleName();

    public static String digestString(String string) {
        if (string == null) {
            return "";
        }

        try {
            if (md == null) {
                md = MessageDigest.getInstance("MD5");
            } else {
                md.reset();
            }
            byte[] digest = md.digest(string.getBytes("UTF-8"));
            return new BigInteger(1, digest).toString(16);
        } catch (Exception e) {
            Log.e(TAG, "Exception getting md5sum for string \"" + string + "\"", e);
            return "";
        }
    }

    public static String digestFile(File file) {
        InputStream is = null;

        try {
            if (md == null) {
                md = MessageDigest.getInstance("MD5");
            } else {
                md.reset();
            }
            is = new DigestInputStream(new FileInputStream(file), md);
            byte[] bytes = new byte[8192];
            while (is.read(bytes) > 0) {
            }
        } catch (java.security.NoSuchAlgorithmException nsa) {
            Log.e(TAG, "MD5 algorithm not supported", nsa);
            return "";
        } catch (java.io.FileNotFoundException nfe) {
            Log.e(TAG, "File not found", nfe);
            return "";
        } catch (java.io.IOException ioe) {
            Log.e(TAG, "IO exception", ioe);
            return "";
        } finally {
            try {
                is.close();
            } catch (java.io.IOException e) {
                e.printStackTrace();
            }
        }

        byte[] digest = md.digest();
        return new BigInteger(1, digest).toString(16);
    }
}




Java Source Code List

com.chrisplus.ltm.LogService.java
com.chrisplus.ltm.MainActivity.java
com.chrisplus.ltm.activies.ErrorDialogActivity.java
com.chrisplus.ltm.core.CoreLogger.java
com.chrisplus.ltm.core.CoreParser.java
com.chrisplus.ltm.utils.CharArrayStringAATree.java
com.chrisplus.ltm.utils.CharArray.java
com.chrisplus.ltm.utils.Constants.java
com.chrisplus.ltm.utils.ItemNotFoundException.java
com.chrisplus.ltm.utils.MD5Sum.java
com.chrisplus.ltm.utils.NetStat.java
com.chrisplus.ltm.utils.ShellCommand.java
com.chrisplus.ltm.utils.StringPool.java
com.chrisplus.ltm.utils.SysUtils.java