Android Open Source - JiangHomeStyle_Android_Phone M D5 Tools From Project Back to project page JiangHomeStyle_Android_Phone .
License The source code is released under:
Apache License
If you think the Android project JiangHomeStyle_Android_Phone 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 package com.cidesign.jianghomestylephone.tools;
/ * f r o m w w w . j a v a 2 s . c o m * /
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Tools
{
/**
* ??????????????????????????????? 16 ???????????,apache?????????????????????????????????
*/
protected static char hexDigits[] = { '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , 'a' , 'b' , 'c' , 'd' , 'e' , 'f' };
protected static MessageDigest messagedigest = null;
static
{
try
{
messagedigest = MessageDigest.getInstance("MD5" );
}
catch (NoSuchAlgorithmException nsaex)
{
System.err.println(MD5Tools.class.getName() + "?????????MessageDigest?????MD5Util??" );
nsaex.printStackTrace();
}
}
/**
* ???????????md5????
*
* @param s
* @return
*/
public static String getMD5String(String s)
{
return getMD5String(s.getBytes());
}
/**
* ??????????md5??????????????????md5???????
*
* @param password
* ??????????
* @param md5PwdStr
* ?????md5?????
* @return
*/
public static boolean checkPassword(String password, String md5PwdStr)
{
String s = getMD5String(password);
return s.equals(md5PwdStr);
}
/**
* ?????????md5????
*
* @param file
* @return
* @throws IOException
*/
public static String getFileMD5String(File file) throws IOException
{
InputStream fis;
fis = new FileInputStream(file);
byte [] buffer = new byte [1024];
int numRead = 0;
while ((numRead = fis.read(buffer)) > 0)
{
messagedigest.update(buffer, 0, numRead);
}
fis.close();
return bufferToHex(messagedigest.digest());
}
/**
* JDK1.4????????MappedByteBuffer?????????update?????????????????????????MappedByteBuffer??
* ????????? FileChannel.map ???????MappedByteBuffer ?????????????????????? ?????
* FileChannel.close ???????????????????????FileChannel?????????? unmap ???????
* ???????????????????????
*
* ????????
*
* @param file
* @return
* @throws IOException
*/
public static String getFileMD5String_old(File file) throws IOException
{
FileInputStream in = new FileInputStream(file);
FileChannel ch = in.getChannel();
MappedByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0, file.length());
messagedigest.update(byteBuffer);
return bufferToHex(messagedigest.digest());
}
public static String getMD5String(byte [] bytes)
{
messagedigest.update(bytes);
return bufferToHex(messagedigest.digest());
}
private static String bufferToHex(byte bytes[])
{
return bufferToHex(bytes, 0, bytes.length);
}
private static String bufferToHex(byte bytes[], int m, int n)
{
StringBuffer stringbuffer = new StringBuffer(2 * n);
int k = m + n;
for (int l = m; l < k; l++)
{
appendHexPair(bytes[l], stringbuffer);
}
return stringbuffer.toString();
}
private static void appendHexPair(byte bt, StringBuffer stringbuffer)
{
char c0 = hexDigits[(bt & 0xf0) >> 4];// ??????? 4 ??????????, >>>
// ???????????????????????,????????????????????
char c1 = hexDigits[bt & 0xf];// ??????? 4 ??????????
stringbuffer.append(c0);
stringbuffer.append(c1);
}
}
Java Source Code List com.cidesign.jianghomestylephone.DetailActivity.java com.cidesign.jianghomestylephone.JiangActivity.java com.cidesign.jianghomestylephone.MainActivity.java com.cidesign.jianghomestylephone.SplashActivity.java com.cidesign.jianghomestylephone.adapter.CommunityViewpagerAdapter.java com.cidesign.jianghomestylephone.adapter.HumanityViewpagerAdapter.java com.cidesign.jianghomestylephone.adapter.LandscapeViewpagerAdapter.java com.cidesign.jianghomestylephone.adapter.LayoutCaculateAdapter.java com.cidesign.jianghomestylephone.adapter.StoryViewpagerAdapter.java com.cidesign.jianghomestylephone.async.AsyncDownTask.java com.cidesign.jianghomestylephone.async.AsyncInitCommunityData.java com.cidesign.jianghomestylephone.async.AsyncInitData.java com.cidesign.jianghomestylephone.async.AsyncInitHomeData.java com.cidesign.jianghomestylephone.async.AsyncInitHumanityData.java com.cidesign.jianghomestylephone.async.AsyncInitLandscapeData.java com.cidesign.jianghomestylephone.async.AsyncInitStoryData.java com.cidesign.jianghomestylephone.db.DatabaseConfigUtil.java com.cidesign.jianghomestylephone.db.DatabaseHelper.java com.cidesign.jianghomestylephone.entity.ArticleEntity.java com.cidesign.jianghomestylephone.entity.FileListEntity.java com.cidesign.jianghomestylephone.entity.LayoutEntity.java com.cidesign.jianghomestylephone.entity.RelativeLayoutRulesEntity.java com.cidesign.jianghomestylephone.http.ArticalOperation.java com.cidesign.jianghomestylephone.http.DownLoadThread.java com.cidesign.jianghomestylephone.service.DownloadService.java com.cidesign.jianghomestylephone.tools.CategoryDataLoadingLogic.java com.cidesign.jianghomestylephone.tools.FileOperationTools.java com.cidesign.jianghomestylephone.tools.JiangCategory.java com.cidesign.jianghomestylephone.tools.LayoutMarginSetting.java com.cidesign.jianghomestylephone.tools.LoadingDataFromDB.java com.cidesign.jianghomestylephone.tools.LoadingImageTools.java com.cidesign.jianghomestylephone.tools.MD5Tools.java com.cidesign.jianghomestylephone.tools.StorageUtils.java com.cidesign.jianghomestylephone.tools.TimeTools.java com.cidesign.jianghomestylephone.tools.WidgetCache.java com.cidesign.jianghomestylephone.tools.XmlParseTools.java com.cidesign.jianghomestylephone.version.NetworkTool.java com.cidesign.jianghomestylephone.version.VersionConfig.java com.cidesign.jianghomestylephone.version.VersionUpdate.java com.cidesign.jianghomestylephone.widget.CommunityRelativeLayout.java com.cidesign.jianghomestylephone.widget.CustomScrollView.java com.cidesign.jianghomestylephone.widget.HScrollViewTouchLogic.java com.cidesign.jianghomestylephone.widget.HumanityRelativeLayout.java com.cidesign.jianghomestylephone.widget.LandscapeRelativeLayout.java com.cidesign.jianghomestylephone.widget.PopMenu.java com.cidesign.jianghomestylephone.widget.StoryRelativeLayout.java org.apache.tools.zip.AbstractUnicodeExtraField.java org.apache.tools.zip.AsiExtraField.java org.apache.tools.zip.CentralDirectoryParsingZipExtraField.java org.apache.tools.zip.ExtraFieldUtils.java org.apache.tools.zip.FallbackZipEncoding.java org.apache.tools.zip.GeneralPurposeBit.java org.apache.tools.zip.JarMarker.java org.apache.tools.zip.NioZipEncoding.java org.apache.tools.zip.Simple8BitZipEncoding.java org.apache.tools.zip.UnicodeCommentExtraField.java org.apache.tools.zip.UnicodePathExtraField.java org.apache.tools.zip.UnixStat.java org.apache.tools.zip.UnparseableExtraFieldData.java org.apache.tools.zip.UnrecognizedExtraField.java org.apache.tools.zip.UnsupportedZipFeatureException.java org.apache.tools.zip.Zip64ExtendedInformationExtraField.java org.apache.tools.zip.Zip64Mode.java org.apache.tools.zip.Zip64RequiredException.java org.apache.tools.zip.ZipConstants.java org.apache.tools.zip.ZipEightByteInteger.java org.apache.tools.zip.ZipEncodingHelper.java org.apache.tools.zip.ZipEncoding.java org.apache.tools.zip.ZipEntry.java org.apache.tools.zip.ZipExtraField.java org.apache.tools.zip.ZipFile.java org.apache.tools.zip.ZipLong.java org.apache.tools.zip.ZipOutputStream.java org.apache.tools.zip.ZipShort.java org.apache.tools.zip.ZipUtil.java