Java Digest digest(String uri)

Here you can find the source of digest(String uri)

Description

digest

License

Open Source License

Declaration

public static String digest(String uri) 

Method Source Code

//package com.java2s;
/**/*  w w  w.  ja v a 2 s.  co m*/
 * Copyright (C) 2009 G?nter Ladwig (gla at aifb.uni-karlsruhe.de)
 * 
 * This file is part of the graphindex project.
 *
 * graphindex is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2
 * as published by the Free Software Foundation.
 * 
 * graphindex 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 General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with graphindex.  If not, see <http://www.gnu.org/licenses/>.
 */

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

public class Main {
    public static String digest(String uri) {
        try {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.update(uri.getBytes());
            byte messageDigest[] = algorithm.digest();

            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < messageDigest.length; i++) {
                hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
            }
            return "_" + hexString.toString();
        } catch (NoSuchAlgorithmException nsae) {
        }

        return uri.replaceAll("\\/|:|\\.|#|\\?|&|\\+|-|~", "_");
    }
}

Related

  1. digest(String strSrc, String encName)
  2. digest(String text)
  3. digest(String text, String algorithm)
  4. digest(String token)
  5. digest(String type, byte[] bytes)
  6. digest(String value, byte[] salt, int iterations)
  7. digest(String value, String algorithm)
  8. digestBased(String text)
  9. digestBySHA256(byte[] source)