Example usage for org.apache.wicket.util.crypt Base64 encodeBase64String

List of usage examples for org.apache.wicket.util.crypt Base64 encodeBase64String

Introduction

In this page you can find the example usage for org.apache.wicket.util.crypt Base64 encodeBase64String.

Prototype

public static String encodeBase64String(final byte[] binaryData) 

Source Link

Document

Encodes binary data using the base64 algorithm into 76 character blocks separated by CRLF.

Usage

From source file:org.apache.syncope.client.enduser.util.SaltGenerator.java

License:Apache License

public static String generate(final String input) {
    // generate salt
    byte[] salt = new byte[16];
    // fill array with random bytes
    new SecureRandom().nextBytes(salt);
    // create digest with MD5
    return DigestUtils.md2Hex(input + Base64.encodeBase64String(salt));
}

From source file:org.wicketstuff.html5.image.CanvasImage.java

License:Apache License

/**
 * Renders the complete image tag with the base64 encoded content.
 *//*from   w w w  .  ja v a  2  s  .c o  m*/
@Override
protected void onComponentTag(ComponentTag tag) {
    checkComponentTag(tag, "img");
    super.onComponentTag(tag);

    IResourceStream packageResourceStream = packageResourceReference.getResource().getResourceStream();
    if (packageResourceStream != null) {
        try {
            StringBuilder builder = new StringBuilder();
            builder.append("data:");
            builder.append(packageResourceStream.getContentType());
            builder.append(";base64,");
            byte[] bytes = new byte[(int) packageResourceStream.length().bytes()];
            DataInputStream dataInputStream = new DataInputStream(packageResourceStream.getInputStream());
            dataInputStream.readFully(bytes);
            builder.append(Base64.encodeBase64String(bytes));
            tag.put("src", builder.toString());
        } catch (Exception e) {
            throw new WicketRuntimeException("An error occured while reading the package resource stream", e);
        }
    } else {
        // If the package resource stream is not set create an empty image
        tag.put("src", "#");
        tag.put("style", "display:none;");
    }
}