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.lib.security.util.DataSignature.java

public PublicKey decodePublicKey(String encodedPublicKey) throws GeneralSecurityException {
    byte[] bytes = Base64.decodeBase64(encodedPublicKey);
    X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(bytes);
    KeyFactory keyFactory = KeyFactory.getInstance("DSA", "SUN");
    return keyFactory.generatePublic(pubKeySpec);
}

From source file:de.rub.nds.burp.utilities.attacks.signatureFaking.helper.CertificateHandler.java

public CertificateHandler(final String cert) throws CertificateHandlerException {
    try {//from  w  ww. j  av a2s.  c  o m
        certFactory = CertificateFactory.getInstance("X.509");
        certificate = (X509Certificate) certFactory
                .generateCertificate(new ByteArrayInputStream(Base64.decodeBase64(cert)));
        originalPublicKey = certificate.getPublicKey();
    } catch (CertificateException e) {
        throw new CertificateHandlerException(e);
    }
}

From source file:com.intuit.tank.http.multipart.MultiPartRequest.java

@Override
public void setBody(String bodyEncoded) {
    String s = new String(Base64.decodeBase64(bodyEncoded));
    String boundary = StringUtils.substringBefore(s, "\r\n").substring(2);
    super.setBody(s);
    try {//from   w  w w .j av a 2  s .com
        // s = getBody();
        @SuppressWarnings("deprecation")
        MultipartStream multipartStream = new MultipartStream(
                new ByteArrayInputStream(Base64.decodeBase64(bodyEncoded)), boundary.getBytes());
        boolean nextPart = multipartStream.skipPreamble();
        while (nextPart) {
            String header = multipartStream.readHeaders();
            // process headers
            // create some output stream
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            multipartStream.readBodyData(bos);
            PartHolder p = new PartHolder(bos.toByteArray(), header);
            parameters.add(p);
            nextPart = multipartStream.readBoundary();
        }
    } catch (MultipartStream.MalformedStreamException e) {
        LOG.error(e.toString(), e);
        // the stream failed to follow required syntax
    } catch (IOException e) {
        LOG.error(e.toString(), e);
        // a read or write error occurred
    }
}

From source file:io.druid.query.aggregation.hyperloglog.PreComputedHyperUniquesSerde.java

@Override
public ComplexMetricExtractor getExtractor() {
    return new ComplexMetricExtractor() {
        @Override/*from ww w .  ja  va 2s  .c o m*/
        public Class<HyperLogLogCollector> extractedClass() {
            return HyperLogLogCollector.class;
        }

        @Override
        public HyperLogLogCollector extractValue(InputRow inputRow, String metricName) {
            Object rawValue = inputRow.getRaw(metricName);

            if (rawValue == null) {
                return HyperLogLogCollector.makeLatestCollector();
            } else if (rawValue instanceof HyperLogLogCollector) {
                return (HyperLogLogCollector) rawValue;
            } else if (rawValue instanceof byte[]) {
                return HyperLogLogCollector.makeLatestCollector().fold(ByteBuffer.wrap((byte[]) rawValue));
            } else if (rawValue instanceof String) {
                return HyperLogLogCollector.makeLatestCollector()
                        .fold(ByteBuffer.wrap(Base64.decodeBase64((String) rawValue)));
            }

            throw new ISE("Object is not of a type[%s] that can be deserialized to HyperLogLog.",
                    rawValue.getClass());
        }
    };
}

From source file:eu.europa.ejusticeportal.dss.applet.controller.cb.GetSealedPdfCbHandler.java

/**
 * Handle the callback/*from   ww w. ja v a2  s  . c o  m*/
 * @param the callback XML
 */
public void doHandle(String xml) throws CodeException {
    PDFHome pdfHome = PDFHome.getInstance();
    synchronized (pdfHome) {
        SealedPDF sealedPdf = (SealedPDF) fromString(xml);
        pdfHome.setSealedPdf(Base64.decodeBase64(sealedPdf.getPdfBase64()), sealedPdf.getSignDate());
        pdfHome.setPdfName(sealedPdf.getFileName());
        pdfHome.notifyAll();
    }
    AppletInitSemaphore.getInstance().setSealedPdfReady(true);
    UIControllerHome.getInstance().getUiController().eval(UIFunction.showOpenSealedPdfPrompt);
}

From source file:com.fruit.core.util.IWebUtils.java

/**
 * ??//from   w  ww .  ja v a  2s. c  o m
 * @author eason
 * @param request
 * @return
 */
public static SysUser getCurrentSysUser(HttpServletRequest request) {
    SysUser sysUser = getCurrentSysUser(request.getSession());
    if (sysUser == null) {
        String token = CookieUtils.getCookieByName(request, "token");
        if (CommonUtils.isNotEmpty(token)) {
            String[] tokenArray = new String(Base64.decodeBase64(token)).split(":");
            if (tokenArray.length == 3) {
                String expireTimeStr = tokenArray[1];
                if (new Date(Long.valueOf(expireTimeStr)).after(new Date())) {
                    String name = tokenArray[0];
                    String userInfo = tokenArray[2];
                    SysUser user = SysUser.me
                            .get(CommonUtils.getConditions(new Condition("name", Operators.EQ, name)));
                    if (user != null && user.getStatus().equals(1)) {
                        String userInfo2 = MD5Utils.GetMD5Code(
                                user.getName() + user.getPwd() + expireTimeStr + PropKit.get("app_key"));
                        if (userInfo2.equals(userInfo)) {
                            sysUser = user;
                            setCurrentLoginSysUserToSession(request.getSession(), sysUser);
                        }
                    }
                }
            }
            return sysUser;
        }
    }
    return sysUser;
}

From source file:com.gitblit.transport.ssh.SshKey.java

public PublicKey getPublicKey() {
    if (publicKey == null && rawData != null) {
        // instantiate the public key from the raw key data
        final String[] parts = rawData.split(" ", 3);
        if (comment == null && parts.length == 3) {
            comment = parts[2];/*from   w  w  w .  ja v  a  2 s  .c om*/
        }
        final byte[] bin = Base64.decodeBase64(Constants.encodeASCII(parts[1]));
        try {
            publicKey = new ByteArrayBuffer(bin).getRawPublicKey();
        } catch (SshException e) {
            throw new RuntimeException(e);
        }
    }
    return publicKey;
}

From source file:com.demandware.vulnapp.challenge.impl.CookieChallenge.java

private boolean doesCookieValueGrantAccess(Cookie c) {
    boolean grant = false;
    String value = new String(Base64.decodeBase64(c.getValue()));
    try {/* ww w  . jav a2 s.c o m*/
        JSONObject o = (JSONObject) new JSONParser().parse(value);
        grant = Helpers.isTruthy((String) o.get(ACCESS_KEY));
    } catch (ParseException e) {
        grant = false;
    }
    return grant;
}

From source file:com.gargoylesoftware.htmlunit.protocol.data.DataUrlDecoder.java

/**
 * Decodes a data URL providing simple access to the information contained by the URL.
 * @param url the string representation of the URL to decode
 * @return the {@link DataUrlDecoder} holding decoded information
 * @throws UnsupportedEncodingException if the encoding specified by the data URL is invalid or not
 * available on the JVM/* w  w  w  .j  ava 2 s . c  o  m*/
 * @throws DecoderException if decoding didn't success
 */
public static DataUrlDecoder decodeDataURL(final String url)
        throws UnsupportedEncodingException, DecoderException {
    if (!url.startsWith("data")) {
        throw new IllegalArgumentException("Not a data url: " + url);
    }
    final int comma = url.indexOf(',');
    final String beforeData = url.substring("data:".length(), comma);
    final String mediaType = extractMediaType(beforeData);
    final String charset = extractCharset(beforeData);

    final boolean base64 = beforeData.endsWith(";base64");
    byte[] data = url.substring(comma + 1).getBytes(charset);
    if (base64) {
        data = Base64.decodeBase64(URLCodec.decodeUrl(data));
    } else {
        data = URLCodec.decodeUrl(data);
    }

    return new DataUrlDecoder(data, mediaType, charset);
}

From source file:com.ikon.util.SecureStore.java

/**
 * Base64 decoder
 */
public static byte[] b64Decode(String src) {
    return Base64.decodeBase64(src.getBytes());
}