Here you can find the source of md5(String text, String charset)
Parameter | Description |
---|---|
text | the hashed string |
public static byte[] md5(String text, String charset)
//package com.java2s; /*//w ww. j ava2 s . c o m * Copyright (C) 2006-2016 Talend Inc. - www.talend.com * * This source code is available under agreement available at * %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt * * You should have received a copy of the agreement along with this program; if not, write to Talend SA 9 rue Pages * 92150 Suresnes, France */ import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { /** * Computes an md5 hash of a string. * * @param text the hashed string * @return the string hash * @exception NullPointerException if text is null */ public static byte[] md5(String text, String charset) { // arguments check if (text == null) { throw new NullPointerException("null text"); //$NON-NLS-1$ } try { MessageDigest md = MessageDigest.getInstance("MD5"); //$NON-NLS-1$ md.update(text.getBytes(charset)); return md.digest(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Cannot find MD5 algorithm"); //$NON-NLS-1$ } catch (UnsupportedEncodingException e) { throw new RuntimeException("No such encoding: " + charset); //$NON-NLS-1$ } } }