一个MD5码的算法
这个是一个很简单的MD5码的算法。现在给大家分享一下:
private static String toMd5(byte[] bytes) { try { MessageDigest algorithm = MessageDigest.getInstance("MD5"); algorithm.reset(); algorithm.update(bytes); return toHexString(algorithm.digest(), ""); } catch (NoSuchAlgorithmException e) { Log.v("he--------------------------------ji", "toMd5(): " + e); throw new RuntimeException(e); // 05-20 09:42:13.697: ERROR/hjhjh(256): // 5d5c87e61211ab7a4847f7408f48ac } } private static String toHexString(byte[] bytes, String separator) { StringBuilder hexString = new StringBuilder(); for (byte b : bytes) { hexString.append(Integer.toHexString(0xFF & b)).append(separator); } return hexString.toString(); }
算法很简单,希望对大家有所帮助!
对了,不要忘记引入这两个包:
import java.security.NoSuchAlgorithmException; import android.util.Log;
Log可以不要,我是测试才加上Log的!~~
相关推荐
湾区人工智能 2020-11-20
Pokemogo 2020-11-16
baijingjing 2020-11-16
baijingjing 2020-11-15
Site 2020-11-07
lwnylslwnyls 2020-11-06
justaipanda 2020-11-05
MachineIntellect 2020-11-02
xueyuediana 2020-10-30
GeraldJones 2020-10-30
Tips 2020-10-29
baijingjing 2020-10-28
baijingjing 2020-10-27
硕鼠 2020-10-26
playoffs 2020-10-26
scuyxi 2020-10-25
playoffs 2020-10-25
yise001 2020-10-23