Example usage for org.apache.commons.codec.binary Base64 decodeBase64

List of usage examples for org.apache.commons.codec.binary Base64 decodeBase64

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Base64 decodeBase64.

Prototype

public static byte[] decodeBase64(final byte[] base64Data) 

Source Link

Document

Decodes Base64 data into octets

Usage

From source file:io.warp10.script.processing.image.Pdecode.java

@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {
    Object top = stack.pop();/*from   w w w. ja v  a2  s. com*/

    String data = top.toString();

    if (!(top instanceof String) || !data.startsWith("data:image/")) {
        throw new WarpScriptException(getName() + " expects a base64 data URI on top of the stack.");
    }

    data = data.substring(data.indexOf(",") + 1);

    byte[] bytes = Base64.decodeBase64(data);

    Image awtImage = new ImageIcon(bytes).getImage();

    if (awtImage instanceof BufferedImage) {
        BufferedImage buffImage = (BufferedImage) awtImage;
        int space = buffImage.getColorModel().getColorSpace().getType();
        if (space == ColorSpace.TYPE_CMYK) {
            throw new WarpScriptException(getName() + " only supports RGB images.");
        }
    }

    PImage image = new PImage(awtImage);

    //
    // Check transparency
    //

    if (null != image.pixels) {
        for (int i = 0; i < image.pixels.length; i++) {
            // since transparency is often at corners, hopefully this
            // will find a non-transparent pixel quickly and exit
            if ((image.pixels[i] & 0xff000000) != 0xff000000) {
                image.format = PImage.ARGB;
                break;
            }
        }
    }

    stack.push(image);

    return stack;
}

From source file:net.mindengine.oculus.frontend.web.Auth.java

public static User decodeUser(String encodedString) {
    try {/*from  w  w  w  .j  ava 2  s .  c  o m*/
        ObjectInputStream ois = new ObjectInputStream(
                new ByteArrayInputStream(Base64.decodeBase64(encodedString.getBytes())));
        SealedObject sealedObject = (SealedObject) ois.readObject();
        ois.close();

        Cipher dcipher = Cipher.getInstance("DES");
        dcipher.init(Cipher.DECRYPT_MODE, secrectAuthKey);

        User user = (User) sealedObject.getObject(dcipher);
        return user;
    } catch (Exception e) {
        return null;
    }
}

From source file:it.geosolutions.figis.persistence.dao.util.PwEncoder.java

/**
 * Decode the password on base 64//from   w  w w  .ja  v  a2s  . com
 * @param msg
 * @return
 */
public static String decode(String msg) {
    try {
        SecretKeySpec keySpec = new SecretKeySpec(KEY, "AES");
        Cipher cipher = Cipher.getInstance("AES");
        cipher.init(Cipher.DECRYPT_MODE, keySpec);

        byte[] de64 = Base64.decodeBase64(msg);
        byte[] decrypted = cipher.doFinal(de64);

        return new String(decrypted);
    } catch (NoSuchAlgorithmException ex) {
        throw new RuntimeException("Error while encoding", ex);
    } catch (NoSuchPaddingException ex) {
        throw new RuntimeException("Error while encoding", ex);
    } catch (IllegalBlockSizeException ex) {
        throw new RuntimeException("Error while encoding", ex);
    } catch (BadPaddingException ex) {
        throw new RuntimeException("Error while encoding", ex);
    } catch (InvalidKeyException ex) {
        throw new RuntimeException("Error while encoding", ex);
    }
}

From source file:com.btoddb.chronicle.Event.java

public Event(String body) {
    this.bodyIsText = true;
    if (bodyIsText) {
        this.body = body.getBytes();
    } else {/*from  w  w w  .  j a  v  a 2  s .com*/
        this.body = Base64.decodeBase64(body);
    }
}

From source file:com.webarch.common.lang.Digest.java

/**
 * base64?//from   w w  w .j  a v  a 2 s .c  om
 *
 * @param charset utf-8
 * @param sources 
 * @return ?<code>sources</code>
 */
public static String[] base64Decode(String charset, final String... sources) {
    try {
        if (charset == null || "".equals(charset))
            charset = "UTF-8";
        String[] results = new String[sources.length];
        for (int i = 0; i < sources.length; i++) {
            results[i] = new String(Base64.decodeBase64(sources[i]), charset);
        }
        return results;
    } catch (UnsupportedEncodingException e) {
        return null;
    }
}

From source file:ch.cyberduck.core.irods.IRODSAttributesFinderFeature.java

@Override
public PathAttributes find(final Path file) throws BackgroundException {
    try {/*from  w w  w.j  a va2  s  . c  o m*/
        final IRODSFileSystemAO fs = session.getClient();
        final IRODSFile f = fs.getIRODSFileFactory().instanceIRODSFile(file.getAbsolute());
        if (!f.exists()) {
            throw new NotfoundException(file.getAbsolute());
        }
        final PathAttributes attributes = new PathAttributes();
        final ObjStat stats = fs.getObjStat(f.getAbsolutePath());
        attributes.setModificationDate(stats.getModifiedAt().getTime());
        attributes.setCreationDate(stats.getCreatedAt().getTime());
        attributes.setSize(stats.getObjSize());
        attributes.setChecksum(Checksum.parse(Hex.encodeHexString(Base64.decodeBase64(stats.getChecksum()))));
        attributes.setOwner(stats.getOwnerName());
        attributes.setGroup(stats.getOwnerZone());
        return attributes;
    } catch (JargonException e) {
        throw new IRODSExceptionMappingService().map("Failure to read attributes of {0}", e, file);
    }
}

From source file:com.arwantech.docjavaui.utils.TripleDES.java

public String decrypt(String encryptedString) {
    String decryptedText = null;/*from   w  ww  . ja va 2  s .c o  m*/
    try {
        cipher.init(Cipher.DECRYPT_MODE, key);
        byte[] encryptedText = Base64.decodeBase64(encryptedString.getBytes());
        byte[] plainText = cipher.doFinal(encryptedText);
        decryptedText = new String(plainText);
    } catch (InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) {
        e.printStackTrace();
        decryptedText = "Error decrypts";
    } finally {
        return decryptedText;
    }

}

From source file:com.lling.qiqu.utils.AesUtils.java

/**
 * Encrypts a message using a 128bit Bse64 key using AES.
 *
 * @param key     128bit Base64 AES key//  w  ww  .  j  a v a2  s .c o  m
 * @param message Message to encrypt
 * @return hex encoded encrypted message
 */
public static String encrypt(String key, String message) {
    String encrypted = "";
    try {
        // Generate the secret key specs.
        byte[] keyArray = Base64.decodeBase64(key.getBytes());
        SecretKeySpec skeySpec = new SecretKeySpec(keyArray, "AES");
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
        byte[] encrypt = cipher.doFinal(message.getBytes());
        encrypted = new String(hexCodec.encode(encrypt));
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
    return encrypted;
}

From source file:com.sapienter.jbilling.common.JBCryptoImpl.java

public String decrypt(String cryptedText) {
    Cipher cipher = getCipher();//from  w  ww.  j a  v  a  2  s. co  m
    byte[] crypted = useHexForBinary ? Util.stringToBinary(cryptedText)
            : Base64.decodeBase64(cryptedText.getBytes());
    byte[] result;
    try {
        cipher.init(Cipher.DECRYPT_MODE, mySecretKey, ourPBEParameters);
        result = cipher.doFinal(crypted);
    } catch (GeneralSecurityException e) {
        throw new IllegalArgumentException("Can not decrypt:" + cryptedText, e);
    }
    return new String(result, UTF8);
}

From source file:microsoft.exchange.webservices.data.property.definition.ByteArrayPropertyDefinition.java

/**
 * Parses the specified value./*from  www  .j  a  v a2s  .c o  m*/
 *
 * @param value accepts String
 * @return value
 */
@Override
protected byte[] parse(String value) {
    return Base64.decodeBase64(value);
}