Example usage for org.apache.shiro.codec Hex encode

List of usage examples for org.apache.shiro.codec Hex encode

Introduction

In this page you can find the example usage for org.apache.shiro.codec Hex encode.

Prototype

public static char[] encode(byte[] data) 

Source Link

Document

Converts an array of bytes into an array of characters representing the hexadecimal values of each byte in order.

Usage

From source file:org.sonatype.nexus.ldap.internal.connector.dao.password.MD5PasswordEncoder.java

License:Open Source License

protected String encodeString(String input) {
    InputStream is = new ByteArrayInputStream(input.getBytes());
    String result = null;//ww w  .jav  a  2 s . c o  m
    try {
        byte[] buffer = new byte[1024];
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        int numRead;
        do {
            numRead = is.read(buffer);
            if (numRead > 0) {
                md5.update(buffer, 0, numRead);
            }
        } while (numRead != -1);
        result = new String(Hex.encode(md5.digest()));
    } catch (Exception e) {
    }
    return result;
}