Android UUID Create generateUUID(String value)

Here you can find the source of generateUUID(String value)

Description

generate UUID

License

Open Source License

Declaration

public static UUID generateUUID(String value) 

Method Source Code

//package com.java2s;
/* /*from  www.ja v  a 2  s  . c  om*/
 * SWRVE CONFIDENTIAL
 * 
 * (c) Copyright 2010-2014 Swrve New Media, Inc. and its licensors.
 * All Rights Reserved.
 * 
 * NOTICE: All information contained herein is and remains the property of Swrve
 * New Media, Inc or its licensors.  The intellectual property and technical
 * concepts contained herein are proprietary to Swrve New Media, Inc. or its
 * licensors and are protected by trade secret and/or copyright law.
 * Dissemination of this information or reproduction of this material is
 * strictly forbidden unless prior written permission is obtained from Swrve.
 */

import android.util.Log;

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

import java.util.UUID;

public class Main {
    private static final String LOG_TAG = "SwrveSDK";

    public static UUID generateUUID(String value) {
        return UUID.nameUUIDFromBytes(md5(value).getBytes());
    }

    public static String md5(String text) {
        if (text == null) {
            return null;
        } else {
            try {
                byte[] bytesOfMessage = text.getBytes();
                MessageDigest md5 = MessageDigest.getInstance("MD5");
                byte[] hash = md5.digest(bytesOfMessage);

                StringBuilder hexDigest = new StringBuilder();
                for (int i = 0; i < hash.length; i++) {
                    if ((0xFF & hash[i]) < 0x10) {
                        hexDigest.append("0");
                    }
                    hexDigest.append(Integer.toHexString(0xFF & hash[i]));
                }
                return hexDigest.toString();
            } catch (NoSuchAlgorithmException nsae) {
                Log.wtf(LOG_TAG, "Couldn't find MD5 - what a strange JVM",
                        nsae);
                return "";
            }
        }
    }
}

Related

  1. getRandomUUID()
  2. createUUID()
  3. getUUID()
  4. getNewUUID()
  5. UUID()