Java Hash Calculate getHash(String valueToHash)

Here you can find the source of getHash(String valueToHash)

Description

get Hash

License

Open Source License

Declaration

public static String getHash(String valueToHash) 

Method Source Code


//package com.java2s;
/*/* ww w. j a v  a2  s.  c o  m*/
 * (C) Copyright 2011 Nuxeo SAS (http://nuxeo.com/) and contributors.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser General Public License
 * (LGPL) version 2.1 which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/lgpl.html
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * Contributors:
 *     Nuxeo - initial API and implementation
 */

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Main {
    public static String getHash(String valueToHash) {
        MessageDigest digest;
        try {
            digest = java.security.MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
        digest.update(valueToHash.getBytes());
        byte messageDigest[] = digest.digest();
        StringBuffer hexString = new StringBuffer();
        for (int i = 0; i < messageDigest.length; i++) {
            hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
        }
        return hexString.toString();
    }
}

Related

  1. getHash(String phrase, String algorithm)
  2. getHash(String s)
  3. getHash(String str, String algorithm)
  4. getHash(String strDate)
  5. getHash(String text)
  6. getHash(String var)
  7. getHashChars(byte[] bytes)
  8. getHashedPassword(String plainPassword)
  9. getHashFromString(String str)