public class MD5 {
/**
* Signature String
* @param text string that needs to be signed
* @param key key
* @param input_charset encoding format
* @return Signature Results
*/
public static string sign (string text, string key, String input_charset) {
Text = text + key;
Return Digestutils.md5hex (getcontentbytes (text, input_charset));
}
/**
* Signature String
* @param text string that needs to be signed
* @param sign Signature results
* @param key key
* @param input_charset encoding format
* @return Signature Results
*/
public static Boolean verify (string text, string sign, String key, String input_charset) {
Text = text + key;
String mysign = Digestutils.md5hex (getcontentbytes (text, input_charset));
if (Mysign.equals (sign)) {
return true;
}
else {
return false;
}
}
/**
* @param content
* @param CharSet
* @return
* @throws signatureexception
* @throws unsupportedencodingexception
*/
private static byte[] Getcontentbytes (string content, String charset) {
if (charset = = NULL | | "". Equals (CharSet)) {
return Content.getbytes ();
}
try {
Return Content.getbytes (CharSet);
} catch (Unsupportedencodingexception e) {
throw new RuntimeException ("An error occurred during the MD5 signature, the specified encoding set is incorrect, the encoding set you currently specify is:" + charset);
}
}
}