public static byte[] encrypt(String data, String algorithm)
throws NoSuchAlgorithmException {
return encryptor(data.getBytes(),algorithm);
}
private static byte[] encryptor(byte[] obj, String algorithm)
throws NoSuchAlgorithmException {
MessageDigest msgd = MessageDigest.getInstance(algorithm);
msgd.reset();
msgd.update(obj);
return msgd.digest();
}
public static String byteToString(byte[] arr){
String s = null;
try {
s = new String( arr, "UTF-8" );
} catch (UnsupportedEncodingException ex) {
logger.debug("[byteToString] ",ex);
}
s.replaceAll( " ", "" );
logger.debug("[byteToString] the String: "+s);
return s;
}