Java Utililty Methods MD5 String

List of utility methods to do MD5 String

  1. HOME
  2. Java
  3. M
  4. MD5 String

Description

The list of methods to do MD5 String are organized into topic(s).

Method

MessageDigest md5()
md
try {
 return MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
 throw new Error(e);
String md5(File f)
md
try {
 byte[] buf = new byte[1024];
 MessageDigest md = MessageDigest.getInstance("MD5");
 try (InputStream is = new FileInputStream(f); DigestInputStream dis = new DigestInputStream(is, md);) {
 while (dis.read(buf) >= 0)
 ;
 byte[] digest = md.digest();
...
String md5(File f)
md
MessageDigest md = null;
InputStream is = null;
try {
 md = MessageDigest.getInstance("MD5");
 is = new FileInputStream(f);
 is = new DigestInputStream(is, md);
 byte[] buffer = new byte[8192];
 while (is.read(buffer) != -1) {
...
String md5(File f)
md
try {
 byte[] b = Files.readAllBytes(f.toPath());
 byte[] hash = MessageDigest.getInstance("MD5").digest(b);
 return byteArrayToHex(hash);
} catch (NoSuchAlgorithmException e) {
 throw new IOException(e.getMessage(), e);
String md5(File f)
md
byte[] bytes = new byte[1024];
InputStream is = null;
try {
 MessageDigest md = MessageDigest.getInstance("MD5");
 is = new DigestInputStream(new FileInputStream(f), md);
 while ((is.read(bytes)) >= 0) {
 return hex(md.digest());
...
String md5(File file)
md
if (!file.exists()) {
 return null;
if (!file.isDirectory()) {
 return getMd5ByFile(file);
StringBuffer buf = new StringBuffer();
Stack<File> stack = new Stack<File>();
...
String md5(File file)
md
MessageDigest md = MessageDigest.getInstance("MD5");
FileInputStream fis = new FileInputStream(file);
byte[] dataBytes = new byte[1024];
int nread = 0;
while ((nread = fis.read(dataBytes)) != -1) {
 md.update(dataBytes, 0, nread);
fis.close();
...
String md5(File file)
Md5.
MessageDigest md = MessageDigest.getInstance("MD5");
InputStream is = new FileInputStream(file);
is = new DigestInputStream(is, md);
byte[] buf = new byte[2048];
@SuppressWarnings("unused")
int read;
while ((read = is.read(buf)) != -1) {
is.close();
byte[] digest = md.digest();
return new BigInteger(1, digest).toString(16);
String md5(File gcdZipFile)
md
try {
 MessageDigest md5 = MessageDigest.getInstance("MD5");
 try (InputStream is = new BufferedInputStream(new FileInputStream(gcdZipFile))) {
 byte[] bytes = new byte[4 * 1024 * 1024];
 int len;
 while ((len = is.read(bytes)) >= 0) {
 md5.update(bytes, 0, len);
 return String.format("%032x", new BigInteger(1, md5.digest()));
} catch (NoSuchAlgorithmException e) {
 throw new IOException(e);
String md5(final File file)
md
try {
 final InputStream fin = new FileInputStream(file);
 final MessageDigest md5 = MessageDigest.getInstance("MD5");
 byte[] buffer = new byte[1024];
 int read;
 while ((read = fin.read(buffer)) > 0) {
 md5.update(buffer, 0, read);
 fin.close();
 byte[] digest = md5.digest();
 if (digest == null)
 return null;
 String hash = "";
 for (int i = 0; i < digest.length; i++) {
 hash += Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1);
 return hash;
} catch (Exception e) {
 return null;


AltStyle によって変換されたページ (->オリジナル) /