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.streamsets.pipeline.stage.processor.base64.Base64DecodingProcessor.java

@Override
protected Field processField(Record record, byte[] fieldData) throws OnRecordErrorException {
    if (!Base64.isBase64(fieldData)) {
        throw new OnRecordErrorException(DataFormatErrors.DATA_FORMAT_302, record.toString());
    }//from  w  w  w .  j  a  v a 2  s.com
    return Field.create(Base64.decodeBase64(fieldData));
}

From source file:com.enonic.cms.server.service.portal.security.BasicAuthInterceptor.java

private String[] getAuthCredentials(HttpServletRequest req) {
    String auth = req.getHeader("Authorization");
    if (auth == null) {
        return null;
    }/*from w  w w. j  a v a 2s  . c o m*/

    String[] tmp = auth.split(" ");
    if (tmp.length < 2) {
        return null;
    }

    if (!"basic".equalsIgnoreCase(tmp[0])) {
        return null;
    }

    String authStr = new String(Base64.decodeBase64(tmp[1].getBytes()));

    String[] credentials = authStr.split(":");

    if (credentials == null) {
        return null;
    }

    // Set blank password if none provided
    if (credentials.length == 1) {
        return new String[] { credentials[0], "" };
    } else if (credentials.length == 2) {
        return credentials;
    } else {
        return null;
    }
}

From source file:net.sf.hajdbc.codec.crypto.CipherCodec.java

/**
 * {@inheritDoc}/* w w w.  j  a va  2  s. c  o m*/
 * @see net.sf.hajdbc.codec.Codec#decode(java.lang.String)
 */
@Override
public String decode(String value) throws SQLException {
    try {
        Cipher cipher = Cipher.getInstance(this.key.getAlgorithm());

        cipher.init(Cipher.DECRYPT_MODE, this.key);

        return new String(cipher.doFinal(Base64.decodeBase64(value.getBytes())));
    } catch (GeneralSecurityException e) {
        throw new SQLException(e);
    }
}

From source file:co.cask.cdap.security.auth.AccessTokenTransformer.java

/**
 *
 * @param accessToken is the access token from Authorization header in HTTP Request
 * @return the serialized access token identifer
 * @throws IOException// www  . ja  v  a2s  .c o  m
 */
public AccessTokenIdentifierPair transform(String accessToken) throws IOException {
    byte[] decodedAccessToken = Base64.decodeBase64(accessToken);
    AccessToken accessTokenObj = accessTokenCodec.decode(decodedAccessToken);
    AccessTokenIdentifier accessTokenIdentifierObj = accessTokenObj.getIdentifier();
    byte[] encodedAccessTokenIdentifier = accessTokenIdentifierCodec.encode(accessTokenIdentifierObj);
    return new AccessTokenIdentifierPair(Base64.encodeBase64String(encodedAccessTokenIdentifier).trim(),
            accessTokenIdentifierObj);
}

From source file:com.quinsoft.zeidon.domains.Base64BlobDomain.java

@Override
public Object convertExternalValue(Task task, AttributeInstance attributeInstance, AttributeDef attributeDef,
        String contextName, Object externalValue) {
    if (externalValue instanceof CharSequence)
        return new Blob(Base64.decodeBase64(externalValue.toString()));

    return super.convertExternalValue(task, attributeInstance, attributeDef, contextName, externalValue);
}

From source file:info.bonjean.beluga.util.CryptoUtil.java

public static String passwordDecrypt(String text, String strKey) {
    return new String(decryptBlowfish(Base64.decodeBase64(text.getBytes()), strKey)).trim();
}

From source file:cn.lynx.emi.license.ViewLicense.java

private static final String _decrypt(String data) {
    byte[] corekey = Base64.decodeBase64(LICENSE_CORE_KEY);
    byte[] rawData = Base64.decodeBase64(data);

    X509EncodedKeySpec x509EncodedKeySpec = new X509EncodedKeySpec(corekey);
    try {/* ww w  .  j a v a 2s  . c  om*/
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        Key publicKey = keyFactory.generatePublic(x509EncodedKeySpec);

        Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
        cipher.init(Cipher.DECRYPT_MODE, publicKey);

        return new String(cipher.doFinal(rawData), "UTF-8");
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.dv.sharer.mobile.rest.impl.ImageAndroidRestClient.java

public byte[] downloadFile(String id) throws Exception {
    String url = getUrlAndPath() + id;
    String response;//from   w  ww.  j  a  va 2 s .co m
    try {
        HttpGet get = getDownloadGET(url);
        HttpResponse httpResponse = getHttpclient().execute(get);
        response = getResponse(httpResponse);
    } catch (Exception e) {
        Log.e(TAG, "Error handling update", e);
        throw e;
    }
    return Base64.decodeBase64(response);
}

From source file:Conexion.newClass.java

public String Decode(String textoEncriptado) throws Exception {

    String secretKey = "mailEncrypted"; //llave para encriptar datos
    String base64EncryptedString = "";

    try {// w w w  .j a  v  a  2 s  .  c o m
        byte[] message = Base64.decodeBase64(textoEncriptado.getBytes("utf-8"));
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] digestOfPassword = md.digest(secretKey.getBytes("utf-8"));
        byte[] keyBytes = Arrays.copyOf(digestOfPassword, 24);
        SecretKey key = new SecretKeySpec(keyBytes, "DESede");

        Cipher decipher = Cipher.getInstance("DESede");
        decipher.init(Cipher.DECRYPT_MODE, key);

        byte[] plainText = decipher.doFinal(message);

        base64EncryptedString = new String(plainText, "UTF-8");

    } catch (Exception ex) {
    }
    return base64EncryptedString;
}

From source file:com.github.alinvasile.jsla.web.authority.AuthorizationHeaderAuthorityProvider.java

public Authority retrieveAuthority(ServletRequest request) {

    String user = null;//from  ww  w  .ja  v  a  2s  .  c om

    if (request instanceof HttpServletRequest) {

        if (logger.isDebugEnabled()) {
            logger.debug("retrieveAuthority");
        }

        HttpServletRequest httpServletRequest = (HttpServletRequest) request;

        String authHeader = httpServletRequest.getHeader("authorization");
        if (authHeader != null) {
            String encodedValue = authHeader.split(" ")[1];
            byte[] decodedValue = Base64.decodeBase64(encodedValue.getBytes());

            user = new String(decodedValue);

            user = user.split(":")[0];

            if (logger.isDebugEnabled()) {
                logger.debug("Found user: " + user);
            }

            return DefaultAuthorityUser.createUsernameOnlyUser(user);
        }

    }

    return DefaultAuthorityUser.createAnonymousUser();
}