Java Hash Code Calculate generateHashUUID(String digestData)

Here you can find the source of generateHashUUID(String digestData)

Description

generate Hash UUID

License

Open Source License

Declaration

public static UUID generateHashUUID(String digestData) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.security.*;
import java.util.*;

public class Main {
    public static UUID generateHashUUID(String digestData) {
        MessageDigest md5;/* www.  j  ava  2 s . c  o m*/
        try {
            md5 = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException exception) {
            return UUID.randomUUID();
        }

        md5.update(digestData.getBytes());
        byte[] data = md5.digest();

        StringBuffer hash = new StringBuffer();
        for (int i = 0; i < data.length; i++) {
            byte b = data[i];

            if ((b & 0xF0) == 0)
                hash.append(0);
            hash.append(Integer.toHexString(b & 0xFF));
        }

        StringBuffer uuid = new StringBuffer();
        uuid.append(hash.substring(0, 8)).append('-');
        uuid.append(hash.substring(8, 12)).append('-');
        uuid.append(hash.substring(12, 16)).append('-');
        uuid.append(hash.substring(16, 20)).append('-');
        uuid.append(hash.substring(20, 32));
        return UUID.fromString(uuid.toString());
    }
}

Related

  1. generateHash(String plainText, String hashType)
  2. generateHash(String serviceUri, String username, String password)
  3. generateHash(String target)
  4. generateHash(String tcString)
  5. generateHashSalt(int length)
  6. hashCode(boolean b)
  7. hashCode(boolean b)
  8. hashCode(boolean bool)
  9. hashCode(boolean bool)