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

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

Introduction

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

Prototype

public Base64(int lineLength, byte[] lineSeparator, final boolean urlSafe) 

Source Link

Document

Creates a Base64 codec used for decoding (all modes) and encoding in URL-unsafe mode.

Usage

From source file:sf.wicklet.ext.application.DefaultWickletCrypt.java

License:Apache License

@Override
public final String encryptUrlSafe(final String text) {
    String s = Lazy.salt16 + text;
    s += TextUtil.toLowerHex8(s.hashCode());
    try {/* w w  w.  j ava  2s .c  o  m*/
        final byte[] encrypted = Lazy.crypt.crypt(salte(Lazy.salt, s.getBytes(CHARACTER_ENCODING)),
                Cipher.ENCRYPT_MODE);
        if (encrypted != null) {
            return PREFIX + new String(new Base64(-1, null, true).encode(encrypted), CHARACTER_ENCODING);
        }
    } catch (final GeneralSecurityException e) {
        log.error("Unable to encrypt text '" + text + "'", e);
    } catch (final UnsupportedEncodingException e) {
        log.error("Unable to encrypt text '" + text + "'", e);
    }
    return null;
}