Example usage for org.apache.shiro.codec CodecSupport toString

List of usage examples for org.apache.shiro.codec CodecSupport toString

Introduction

In this page you can find the example usage for org.apache.shiro.codec CodecSupport toString.

Prototype

public static String toString(byte[] bytes, String encoding) throws CodecException 

Source Link

Document

Converts the specified byte array to a String using the specified character encoding.

Usage

From source file:de.elomagic.mag.utils.SimpleCrypt.java

License:Apache License

public static String decrypt(String encryptedBase64) throws IOException {
    try {// w w w.jav a  2 s  . co m
        if (!isEncryptedValue(encryptedBase64)) {
            throw new IOException("This value is not encapsulated as an encrypted value. Unable to decrypt.");
        }

        byte[] encryptedBytes = Base64.decode(encryptedBase64.substring(1, encryptedBase64.length() - 1));

        ByteSource decrypted = CIPHER.decrypt(encryptedBytes, getMasterKey());

        return CodecSupport.toString(decrypted.getBytes(), "utf-8");
    } catch (Exception ex) {
        LOGGER.error(ex.getMessage(), ex);
        throw ex;
    }
}