Java Utililty Methods Key Create

List of utility methods to do Key Create

Description

The list of methods to do Key Create are organized into topic(s).

Method

StringgetKey(Object obj)
get Key
StringBuffer uid = new StringBuffer(32);
long currentTimeMillis = System.currentTimeMillis();
uid.append(toHex((int) (currentTimeMillis & -1L), 8));
uid.append(midValueStatic);
uid.append(toHex(System.identityHashCode(new Date()), 8));
uid.append(toHex(getRandom(), 8));
return uid.toString();
KeygetKey(String keyString)
get Key
byte[] bytes = hexStringToByteArray(keyString);
DESKeySpec keySpec = new DESKeySpec(bytes);
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM);
SecretKey key = keyFactory.generateSecret(keySpec);
return key;
KeygetKey(String keyString)
get Key
try {
    byte[] bytes = getBytes(keyString);
    DESKeySpec pass = new DESKeySpec(bytes);
    SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");
    SecretKey s = skf.generateSecret(pass);
    return s;
} catch (Exception e) {
    e.printStackTrace();
...
SecretKeygetKey(String salt, String password)
get Key
try {
    SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
    KeySpec spec = new PBEKeySpec(password.toCharArray(), salt.getBytes(), 1000, 256);
    SecretKey tmp = factory.generateSecret(spec);
    return new SecretKeySpec(tmp.getEncoded(), "AES");
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
    throw new IllegalStateException("cannot create key: " + e.getMessage(), e);
SecretKeySpecgetKey(String siteSecret)
get Key
try {
    byte[] key = siteSecret.getBytes("UTF-8");
    key = Arrays.copyOf(MessageDigest.getInstance("SHA").digest(key), 16);
    return new SecretKeySpec(key, "AES");
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
    e.printStackTrace();
return null;
...
StringgetKeyedDigest(String strSrc, String key)
get Keyed Digest
try {
    MessageDigest md5 = MessageDigest.getInstance("MD5");
    md5.update(strSrc.getBytes("UTF8"));
    String result = "";
    byte[] temp;
    temp = md5.digest(key.getBytes("UTF8"));
    for (int i = 0; i < temp.length; i++) {
        result += Integer.toHexString((0x000000ff & temp[i]) | 0xffffff00).substring(6);
...
CiphergetKeyExchangeCipher()
Returns the key exchange cipher.
try {
    return Cipher.getInstance(getKeyExchangeCiperName());
} catch (NoSuchAlgorithmException ex) {
    return null;
} catch (NoSuchPaddingException ex) {
    return null;
KeyFactorygetKeyFactory()
get Key Factory
KeyFactory keyFactory = null;
try {
    keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
} catch (NoSuchAlgorithmException nsae) {
return keyFactory;
KeyFactorygetKeyFactory()
get Key Factory
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
return keyFactory;
KeyFactorygetKeyFactory()
Returns the signature key factory.
return KeyFactory.getInstance(ALGORITHM_SIGNATURE);