List of utility methods to do Key Create
String | getKey(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(); |
Key | getKey(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; |
Key | getKey(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(); ... |
SecretKey | getKey(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); |
SecretKeySpec | getKey(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; ... |
String | getKeyedDigest(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); ... |
Cipher | getKeyExchangeCipher() Returns the key exchange cipher. try { return Cipher.getInstance(getKeyExchangeCiperName()); } catch (NoSuchAlgorithmException ex) { return null; } catch (NoSuchPaddingException ex) { return null; |
KeyFactory | getKeyFactory() get Key Factory KeyFactory keyFactory = null; try { keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); } catch (NoSuchAlgorithmException nsae) { return keyFactory; |
KeyFactory | getKeyFactory() get Key Factory KeyFactory keyFactory = KeyFactory.getInstance("RSA"); return keyFactory; |
KeyFactory | getKeyFactory() Returns the signature key factory. return KeyFactory.getInstance(ALGORITHM_SIGNATURE);
|