Java Key Create getKey(Object obj)

Here you can find the source of getKey(Object obj)

Description

get Key

License

Apache License

Declaration

public static String getKey(Object obj) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.security.SecureRandom;
import java.util.Date;

public class Main {
    private static SecureRandom seederStatic = null;
    private static String midValueStatic = null;

    public static String getKey(Object obj) {
        StringBuffer uid = new StringBuffer(32);

        // get the system time
        long currentTimeMillis = System.currentTimeMillis();
        uid.append(toHex((int) (currentTimeMillis & -1L), 8));

        // get the internet address
        uid.append(midValueStatic);//  w  w  w. j ava  2 s  .c o m

        // get the object hash value
        uid.append(toHex(System.identityHashCode(new Date()), 8));

        // get the random number
        uid.append(toHex(getRandom(), 8));

        return uid.toString();
    }

    public static String getKey() {
        StringBuffer uid = new StringBuffer(32);

        // get the system time
        long currentTimeMillis = System.currentTimeMillis();
        uid.append(toHex((int) (currentTimeMillis & -1L), 8));

        // get the internet address
        uid.append(midValueStatic);

        // get the random number
        uid.append(toHex(getRandom(), 8));

        return uid.toString();
    }

    private static String toHex(int value, int length) {
        char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
        StringBuffer buffer = new StringBuffer(length);
        int shift = length - 1 << 2;
        for (int i = -1; ++i < length;) {
            buffer.append(hexDigits[value >> shift & 0xf]);
            value <<= 4;
        }

        return buffer.toString();
    }

    private static synchronized int getRandom() {
        return seederStatic.nextInt();
    }
}

Related

  1. getKey(InputStream is)
  2. getKey(int size)
  3. getKey(KeyStore keystore, String alias, String password)
  4. getKey(KeyStore keyStore, String password, String orgName)
  5. getKey(KeyStore ks, String alias, String pass)
  6. getKey(String keyString)
  7. getKey(String keyString)
  8. getKey(String salt, String password)
  9. getKey(String siteSecret)