private static Key getKey(String key) { try { byte[] bytes = StringUtil.getAsciiBytes(key); DESKeySpec pass = new DESKeySpec(bytes); SecretKeyFactory skf = SecretKeyFactory.getInstance("DES"); SecretKey s = skf.generateSecret(pass); return s; } catch (Exception e) { e.printStackTrace(); } return null; } }
private static Key getKey(String key) { try { byte[] bytes = StringUtil.getAsciiBytes(key); DESKeySpec pass = new DESKeySpec(bytes); SecretKeyFactory skf = SecretKeyFactory.getInstance("DES"); SecretKey s = skf.generateSecret(pass); return s; } catch (Exception e) { e.printStackTrace(); } return null; } }
/** * Hashes the input String into a Base-64 encoded hashed String. * <ul> * <li>MD5 - hash is always 24 char base-64 * <li>SHA1 - hash is always 28 char base-64 * <li>SHA256 - hash is always 44 char base-64 * <li>SHA512 - hash is always 88 char base-64 * </ul> * @param string0 The String to hash. This assumes its an ASCII string. * @return The Base-64 encoded hashed String * @throws NoSuchAlgorithmException */ public String toHashedBase64String(String string0) throws NoSuchAlgorithmException { return this.toHashedBase64String(StringUtil.getAsciiBytes(string0)); }
/** * Hashes the input String into a Base-64 encoded hashed String. * <ul> * <li>MD5 - hash is always 24 char base-64 * <li>SHA1 - hash is always 28 char base-64 * <li>SHA256 - hash is always 44 char base-64 * <li>SHA512 - hash is always 88 char base-64 * </ul> * @param string0 The String to hash. This assumes its an ASCII string. * @return The Base-64 encoded hashed String * @throws NoSuchAlgorithmException */ public String toHashedBase64String(String string0) throws NoSuchAlgorithmException { return this.toHashedBase64String(StringUtil.getAsciiBytes(string0)); }
/** * Hashes the input String into a hex encoded hashed String. * <br> * <ul> * <li>MD5 - hash is always 32 char hex string * <li>SHA1 - hash is always 40 char hex string * <li>SHA256 - hash is always 64 char hex string * <li>SHA512 - hash is always 128 char hex string * </ul> * @param string0 The String to hash. This assumes its an ASCII string. * @return The hex encoded hashed String * @throws NoSuchAlgorithmException */ public String toHashedHexString(String string0) throws NoSuchAlgorithmException { return this.toHashedHexString(StringUtil.getAsciiBytes(string0)); }
/** * Hashes the input String into a hex encoded hashed String. * <br> * <ul> * <li>MD5 - hash is always 32 char hex string * <li>SHA1 - hash is always 40 char hex string * <li>SHA256 - hash is always 64 char hex string * <li>SHA512 - hash is always 128 char hex string * </ul> * @param string0 The String to hash. This assumes its an ASCII string. * @return The hex encoded hashed String * @throws NoSuchAlgorithmException */ public String toHashedHexString(String string0) throws NoSuchAlgorithmException { return this.toHashedHexString(StringUtil.getAsciiBytes(string0)); }