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:com.glaf.core.util.BinaryUtils.java

/**
 * Converts a Base64-encoded string to the original byte data.
 *
 * @param b64Data/* ww  w  .j  a va 2 s  . c o m*/
 *            a Base64-encoded string to decode.
 *
 * @return bytes decoded from a Base64 string.
 */
public static byte[] fromBase64(String b64Data) {
    return b64Data == null ? null : Base64.decodeBase64(b64Data);
}

From source file:it.greenvulcano.gvesb.virtual.utils.MimeMessageHelper.java

public static MimeMessage decode(String message) throws MessagingException {
    return decode(Base64.decodeBase64(message));
}

From source file:it.classhidra.core.controller.wsController.java

public String getId_UserSOAP(String user, String password, String isCodedInput) {

    if (isCodedInput != null && isCodedInput.toUpperCase().equals("TRUE")) {
        try {/*from  www.j  a  v a  2s .c o  m*/
            user = new String(Base64.decodeBase64(user.getBytes()));
        } catch (Exception e) {
        }
        try {
            password = new String(Base64.decodeBase64(password.getBytes()));
        } catch (Exception e) {
        }
    }

    if (bsController.getUser_config() == null) {
        bsController.setUser_config(new load_users());
        try {
            ((load_users) bsController.getUser_config()).init();
            if (((load_users) bsController.getUser_config()).isReadError())
                ((load_users) bsController.getUser_config()).load_from_resources();
            if (((load_users) bsController.getUser_config()).isReadError())
                ((load_users) bsController.getUser_config())
                        .init(bsController.getAppInit().get_path_config() + bsController.CONST_XML_USERS);
            if (((load_users) bsController.getUser_config()).isReadError())
                bsController.setUser_config(null);
        } catch (bsControllerException je) {
            bsController.setUser_config(null);
        }

    }
    info_user _user = ((load_users) bsController.getUser_config()).get_user(user, password);
    if (_user != null) {

        auth_init auth = new auth_init();

        auth.set_user(_user.getName());
        auth.set_userDesc(_user.getDescription());
        auth.set_ruolo(_user.getGroup());
        auth.set_language(_user.getLanguage());
        auth.set_matricola(_user.getMatriculation());
        auth.set_target(_user.getTarget().replace(';', '^'));
        auth.get_target_property().put(bsConstants.CONST_AUTH_TARGET_ISTITUTION, auth.get_target());
        auth.set_logged(true);
        String redirectSSOID = auth.get_matricola() + "$$" + auth.get_ruolo() + "$$"
                + util_format.dataToString(new Date(), "yyyyMMddHHmm");

        try {
            redirectSSOID = bsController.encrypt(redirectSSOID.toUpperCase());
        } catch (Exception e) {
        }
        return redirectSSOID;
    }

    return "";
}

From source file:com.vmware.o11n.plugin.crypto.service.CryptoEncryptionService.java

/**
 * AES Encryption CBC Mode with PKCS5 Padding
 *
 * @param dataB64 Data to encrypt Base64 encoded
 * @param secretB64 Encryption secret Base64 encoded. For AES128 this should be 128 bits (16 bytes) long. For AES256 this should be 256 bits (32 bytes) long.
 * @param ivB64 Initialization Vector Base64 encoded. 16 bytes long
 * @return Encrypted data Base64 Encoded
 * @throws NoSuchAlgorithmException/*from   ww  w .ja v  a2  s  .  c om*/
 * @throws NoSuchPaddingException
 * @throws InvalidKeyException
 * @throws InvalidAlgorithmParameterException
 * @throws IOException
 * @throws BadPaddingException
 * @throws IllegalBlockSizeException
 */
public String aesEncrypt(String dataB64, String secretB64, String ivB64)
        throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
        InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
    String encryptedB64 = null;

    final byte[] dataBytes = Base64.decodeBase64(dataB64);
    final byte[] secretBytes = Base64.decodeBase64(secretB64);
    final byte[] ivBytes = Base64.decodeBase64(ivB64);
    final Cipher cipher = Cipher.getInstance(AES_CIPHER);

    cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(secretBytes, "AES"),
            new IvParameterSpec(ivBytes, 0, cipher.getBlockSize()));

    encryptedB64 = Base64.encodeBase64String(cipher.doFinal(dataBytes));
    return encryptedB64;
}

From source file:com.qut.middleware.spep.authn.bindings.impl.Artifact.java

public Artifact(String artifact) {
    byte[] rawArtifact;
    try {/*ww w  . j  a  va2s .c  o  m*/
        rawArtifact = Base64.decodeBase64(artifact.getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException(
                "Unable to parse the Base64 SAML artifact token because the required encoding is not supported.",
                e);
    }

    if (rawArtifact.length < 20) {
        throw new IllegalArgumentException(
                "Unable to parse the SAML artifact token, it is not the correct length required by the SAML spec (20 bytes).");
    }

    type = ((int) rawArtifact[0] * 0x100) + (int) rawArtifact[1];
    index = ((int) rawArtifact[2] * 0x100) + (int) rawArtifact[3];

    if (type != 0x0004) {
        throw new IllegalArgumentException(
                "Unable to parse the SAML artifact token, unrecognized type ID: " + type);
    }

    if (rawArtifact.length != 44) {
        throw new IllegalArgumentException(
                "Unable to parse the SAML artifact token, it is not the correct length required by the SAML spec for type ID 0x0004 (44 bytes).");
    }

    this.sourceID = new byte[20];
    for (int i = 0; i < 20; ++i) {
        // Read bytes 4 - 23 inclusive.
        this.sourceID[i] = rawArtifact[4 + i];
    }

    this.messageHandle = new byte[20];
    for (int i = 0; i < 20; ++i) {
        // Read bytes 24 - 43 inclusive.
        this.messageHandle[i] = rawArtifact[24 + i];
    }
}

From source file:net.navasoft.madcoin.backend.services.security.Encrypter.java

/**
 * Instantiates a new encrypter./*from  w w  w.ja  v a2 s  .  c o  m*/
 * 
 * @param keyString
 *            the key string
 * @param ivString
 *            the iv string
 * @since 5/08/2014, 08:03:33 PM
 */
public Encrypter(String keyString, String ivString) {
    try {
        final MessageDigest md = MessageDigest.getInstance("md5");
        final byte[] digestOfPassword = md.digest(Base64.decodeBase64(keyString.getBytes("utf-8")));
        final byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
        for (int j = 0, k = 16; j < 8;) {
            keyBytes[k++] = keyBytes[j++];
        }

        keySpec = new DESedeKeySpec(keyBytes);

        key = SecretKeyFactory.getInstance("DESede").generateSecret(keySpec);

        iv = new IvParameterSpec(ivString.getBytes());
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.intbit.CropImage.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from  w  w w . j  a  v  a2  s  .c  o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */

@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    super.processRequest(request, response);
    response.setContentType("text/html;charset=UTF-8");
    Date date = new Date();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH:mm:ssSSS");
    PrintWriter out = response.getWriter();
    logger.log(Level.INFO, "enter in servlet");
    //        sqlmethods.session = request.getSession(true);
    StringBuffer string_buffer = new StringBuffer();
    boolean check = true;
    try {

        String imageData = request.getParameter("image");

        imageData = imageData.replaceAll("^data:image[^;]+;base64,", "");
        logger.log(Level.INFO, getServletContext().getRealPath(""));
        byte[] data = Base64.decodeBase64(imageData);
        try (OutputStream stream = new FileOutputStream(getServletContext().getRealPath("")
                + "/images/temp_image/" + dateFormat.format(date) + ".png")) {
            stream.write(data);
            response.setContentType("text/plain");
            response.getWriter().write(dateFormat.format(date) + ".png");
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, util.Utility.logMessage(e, "Exception while updating org name:",
                getSqlMethodsInstance().error));

    } finally {
        out.close();
        getSqlMethodsInstance().closeConnection();
    }
}

From source file:com.centurylink.mdw.util.CryptUtil.java

private static byte[] decodeBase64(String inputString) {
    return Base64.decodeBase64(inputString.getBytes());
}

From source file:de.openflorian.crypt.provider.BlowfishCipher.java

@Override
public String decrypt(String str) throws GeneralSecurityException {
    if (key == null || key.isEmpty())
        throw new IllegalStateException("The key is not set or is length=0.");

    if (str == null)
        return null;

    try {/*w  w w .  j a  v  a  2s . co m*/
        SecretKeySpec keySpec;
        keySpec = new SecretKeySpec(key.getBytes("UTF8"), "Blowfish");

        Cipher cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
        cipher.init(Cipher.DECRYPT_MODE, keySpec);

        return new String(cipher.doFinal(Base64.decodeBase64(str.getBytes("UTF8"))), "UTF8");
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new GeneralSecurityException(e.getMessage(), e);
    }
}

From source file:com.ebay.nest.io.sede.lazy.LazyBinary.java

@Override
public void init(ByteArrayRef bytes, int start, int length) {

    byte[] recv = new byte[length];
    System.arraycopy(bytes.getData(), start, recv, 0, length);
    boolean arrayByteBase64 = Base64.isArrayByteBase64(recv);
    if (arrayByteBase64) {
        LOG.debug("Data not contains valid characters within the Base64 alphabet so " + "decoded the data.");
    }/*from  w ww.j  av  a 2 s  .co  m*/
    byte[] decoded = arrayByteBase64 ? Base64.decodeBase64(recv) : recv;
    data.set(decoded, 0, decoded.length);
}