public class Md5FileNameGenerator {
private static final String HASH_ALGORITHM = "MD5";
private static final int RADIX = 10 + 26; // 10 digits + 26 letters
@Override
public String generate(String imageUri) {
byte[] md5 = getMD5(imageUri.getBytes());
BigInteger bi = new BigInteger(md5).abs();//取md5的biginteger的绝对值
return bi.toString(RADIX);//在radix处于2-36之间则输出10为基数的字符串
}
private byte[] getMD5(byte[] data) {
byte[] hash = null;
try {
MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM);//选择MD5算法
digest.update(data);//更新数据
hash = digest.digest();//完成算法并返回结果,MessageDigest重新设置为初始值
} catch (NoSuchAlgorithmException e) {
L.e(e);
}
return hash;
}
}
private static final String HASH_ALGORITHM = "MD5";
private static final int RADIX = 10 + 26; // 10 digits + 26 letters
@Override
public String generate(String imageUri) {
byte[] md5 = getMD5(imageUri.getBytes());
BigInteger bi = new BigInteger(md5).abs();//取md5的biginteger的绝对值
return bi.toString(RADIX);//在radix处于2-36之间则输出10为基数的字符串
}
private byte[] getMD5(byte[] data) {
byte[] hash = null;
try {
MessageDigest digest = MessageDigest.getInstance(HASH_ALGORITHM);//选择MD5算法
digest.update(data);//更新数据
hash = digest.digest();//完成算法并返回结果,MessageDigest重新设置为初始值
} catch (NoSuchAlgorithmException e) {
L.e(e);
}
return hash;
}
}