Here you can find the source of looksLikeValidMd5(String possibleMd5)
Parameter | Description |
---|---|
possibleMd5 | the supposed MD5 hash to check |
public static boolean looksLikeValidMd5(String possibleMd5)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w .j a v a2 s .c o m*/ * MD5 hash values are 32 characters long. */ private static final int MD5_LENGTH = 32; /** * Is the argument a legitimate-seeming MD5 value? * That is, is it the right length (32 characters), and does it consist only of hex digits? * * @param possibleMd5 the supposed MD5 hash to check * @return true if the parameter is a plausible MD5 value */ public static boolean looksLikeValidMd5(String possibleMd5) { return (possibleMd5 != null) && possibleMd5.length() == MD5_LENGTH && possibleMd5.chars().allMatch(c -> isHex((char) c)); } /** * Is the argument character a valid hexadecimal digit? * @param c the candidate character * @return true if it's hex, false otherwise */ public static boolean isHex(char c) { return Character.isDigit(c) || (('a' <= c) && (c <= 'f')) || (('A' <= c) && (c <= 'F')); } }