private static MessageDigest getInstance() { if (INSTANCE == null) { try { INSTANCE = MessageDigest.getInstance("MD5"); } catch (final NoSuchAlgorithmException anE) { BasicLogger.error(anE.toString()); } } return INSTANCE; }
/** * @param aPassword An unencrypted (plain text) password * @param aToBytesEncoding * @param aFromBytesEncoding * @return An encrypted password */ public static String encrypt( final String aPassword, final String aToBytesEncoding, final String aFromBytesEncoding) { String retVal = null; final MessageDigest tmpDigest = Password.getInstance(); if (aPassword != null) { try { final byte[] tmpBytes = tmpDigest.digest(aPassword.getBytes(aToBytesEncoding)); retVal = new String(tmpBytes, aFromBytesEncoding).trim(); } catch (final UnsupportedEncodingException anE) { BasicLogger.error(anE.toString()); } } return retVal; }