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

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

Introduction

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

Prototype

public static byte[] encode(byte[] pArray) 

Source Link

Document

Encodes a byte[] containing binary data, into a byte[] containing characters in the Base64 alphabet.

Usage

From source file:org.archone.ad.ldap.PasswordUtil.java

public static String hashPassword(String password)
        throws NoSuchAlgorithmException, UnsupportedEncodingException {
    MessageDigest algorithm = MessageDigest.getInstance("SHA");

    byte[] salt = new byte[8];

    new Random().nextBytes(salt);

    algorithm.update(password.getBytes());
    algorithm.update(salt);//from w  ww  .  java 2s.  co m
    byte[] hash = algorithm.digest();

    return "{SSHA}" + new String(Base64.encode(ArrayUtils.addAll(hash, salt)));
}