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.pinterest.deployservice.common.CommonUtils.java

public static Map<String, String> decodeScript(Map<String, String> data) throws Exception {
    Map<String, String> decoded = new HashMap<String, String>(data.size());
    for (Map.Entry<String, String> entry : data.entrySet()) {
        decoded.put(entry.getKey(), new String(Base64.decodeBase64(entry.getValue().getBytes("UTF8")), "UTF8"));
    }/*from  w  w  w  .  java2s .  co  m*/
    return decoded;
}

From source file:com.aqnote.shared.cryptology.cert.tool.X509CertTool.java

private static byte[] getCertEncoded(String base64CrtFile) {
    if (StringUtils.isEmpty(base64CrtFile)) {
        return null;
    }//w  w  w.  j  av a2s.  co  m

    String tmpBase64CrtFile = base64CrtFile;
    String headLine = BEGIN_CERT + lineSeparator;
    if (base64CrtFile.startsWith(headLine)) {
        tmpBase64CrtFile = StringUtils.removeStart(base64CrtFile, headLine);
    }
    if (tmpBase64CrtFile.endsWith(END_CERT)) {
        tmpBase64CrtFile = StringUtils.removeEnd(tmpBase64CrtFile, END_CERT);
    }

    return Base64.decodeBase64(tmpBase64CrtFile);
}

From source file:com.cloudant.client.internal.views.PaginationToken.java

/**
 * Generate a PageMetadata object for the page represented by the specified pagination token.
 *
 * @param paginationToken   opaque pagination token
 * @param initialParameters the initial view query parameters (i.e. for the page 1 request).
 * @param <K>               the view key type
 * @param <V>               the view value type
 * @return PageMetadata object for the given page
 *///from   w  w  w  .  ja  v a  2s .c  o m
static <K, V> PageMetadata<K, V> mergeTokenAndQueryParameters(String paginationToken,
        final ViewQueryParameters<K, V> initialParameters) {

    // Decode the base64 token into JSON
    String json = new String(Base64.decodeBase64(paginationToken), Charset.forName("UTF-8"));

    // Get a suitable Gson, we need any adapter registered for the K key type
    Gson paginationTokenGson = getGsonWithKeyAdapter(initialParameters);

    // Deserialize the pagination token JSON, using the appropriate K, V types
    PaginationToken token = paginationTokenGson.fromJson(json, PaginationToken.class);

    // Create new query parameters using the initial ViewQueryParameters as a starting point.
    ViewQueryParameters<K, V> tokenPageParameters = initialParameters.copy();

    // Merge the values from the token into the new query parameters
    tokenPageParameters.descending = token.descending;
    tokenPageParameters.endkey = token.endkey;
    tokenPageParameters.endkey_docid = token.endkey_docid;
    tokenPageParameters.inclusive_end = token.inclusive_end;
    tokenPageParameters.startkey = token.startkey;
    tokenPageParameters.startkey_docid = token.startkey_docid;

    return new PageMetadata<K, V>(token.direction, token.pageNumber, tokenPageParameters);
}

From source file:com.mirth.connect.server.util.DICOMUtil.java

public static byte[] getDICOMMessage(MessageObject message) {
    return Base64.decodeBase64(getDICOMRawData(message).getBytes());
}

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

public String sha512Base64(String dataB64) {
    validateB64(dataB64);
    return Base64.encodeBase64String(DigestUtils.sha512(Base64.decodeBase64(dataB64)));
}

From source file:models.service.impl.FrontendUserServiceImpl.java

@Override
public FrontendUser authenticate(String mail, String password) {
    Logger.info(String.format("Trying to authenticate %s using password ****", mail));
    FrontendUser fe = this.getByMail(mail);
    if (fe == null) {
        Logger.warn("Authentication failed, could not retrieve user from db");
        return null;
    }/*from   ww  w.j  a  v a  2 s .c o m*/

    if (Password.getInstance().check(password.toCharArray(), fe.getPassword().toCharArray(),
            Base64.decodeBase64(fe.getSalt()))) {
        Logger.info("Authetication success. Authenticated as user with id=" + fe.getId());
        return fe;
    } else {
        Logger.warn("Authentication failed. Could not match password");
        return null;
    }
}

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

@Override
public TokenState validate(String token) {
    AccessToken accessToken;/* ww  w  . j  a  v a2s .  co m*/
    TokenState state = TokenState.VALID;
    if (token == null) {
        LOG.debug("Token is missing");
        return TokenState.MISSING;
    }
    byte[] decodedToken = Base64.decodeBase64(token);

    try {
        accessToken = accessTokenCodec.decode(decodedToken);
        tokenManager.validateSecret(accessToken);
    } catch (IOException ioe) {
        state = TokenState.INVALID;
        LOG.debug("Unknown Schema version for Access Token. {}", ioe);
    } catch (InvalidTokenException ite) {
        state = ite.getReason();
        LOG.debug("{} {}", state, ite);
    }
    return state;
}

From source file:io.druid.data.input.thrift.ThriftDeserialization.java

public static byte[] decodeB64IfNeeded(final byte[] src) {
    Preconditions.checkNotNull(src, "src bytes cannot be null");
    if (src.length <= 0) {
        return EMPTY_BYTES;
    }/*from   w  ww .  j a v a2 s .co m*/
    final byte last = src[src.length - 1];
    return (0 == last || '}' == last) ? src : Base64.decodeBase64(src);
}

From source file:com.emc.atmos.api.test.EsuApiJerseyAdapterTest.java

/**
 * Test handling signature failures.  Should throw an exception with
 * error code 1032.//from   w  w  w. j  av a2s.c  o m
 */
@Test
public void testSignatureFailure() throws Exception {
    byte[] goodSecret = config.getSecretKey();
    String secretStr = new String(Base64.encodeBase64(goodSecret), "UTF-8");
    byte[] badSecret = Base64.decodeBase64(secretStr.toUpperCase().getBytes("UTF-8"));
    try {
        // Fiddle with the secret key
        config.setSecretKey(badSecret);
        testCreateEmptyObject();
        Assert.fail("Expected exception to be thrown");
    } catch (EsuException e) {
        Assert.assertEquals("Expected error code 1032 for signature failure", 1032, e.getAtmosCode());
    } finally {
        config.setSecretKey(goodSecret);
    }
}

From source file:io.druid.query.aggregation.datasketches.tuple.doublearray.SketchOperations.java

public static ArrayOfDoublesSketch deserializeFromBase64EncodedString(String str) {
    return deserializeFromByteArray(Base64.decodeBase64(str.getBytes(Charsets.UTF_8)));
}