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.kscs.server.web.source.XMLSourceCode.java

public static String getHibernateProperty() {
    return new String(Base64.decodeBase64(HIBERNATE_PROPERTY.getBytes()));
}

From source file:com.aliyun.openservices.tablestore.hadoop.MultiCriteria.java

public static MultiCriteria deserialize(String in) {
    byte[] buf = Base64.decodeBase64(in);
    ByteArrayInputStream is = new ByteArrayInputStream(buf);
    DataInputStream din = new DataInputStream(is);
    try {// ww w  .  j a  va 2  s  . c om
        return read(din);
    } catch (IOException ex) {
        return null;
    }
}

From source file:com.eviware.soapui.impl.wsdl.submit.transports.http.XOPPartDataSource.java

public InputStream getInputStream() throws IOException {
    try {/*w w  w.j a  v  a2 s . c o  m*/
        if (source != null) {
            return new FileInputStream(source);
        }
        if (SchemaUtils.isInstanceOf(schemaType, XmlHexBinary.type)) {
            return new ByteArrayInputStream(Hex.decodeHex(content.toCharArray()));
        } else if (SchemaUtils.isInstanceOf(schemaType, XmlBase64Binary.type)) {
            return new ByteArrayInputStream(Base64.decodeBase64(content.getBytes()));
        } else
            throw new IOException("Invalid type for XOPPartDataSource; " + schemaType.getName());
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(e.toString());
    }
}

From source file:cf.spring.HttpBasicAuthenticator.java

private String[] parseCredentials(String base64Credentials) {
    final String credentials = new String(Base64.decodeBase64(base64Credentials));
    final int splitIndex = credentials.indexOf(':');
    if (splitIndex < 0) {
        return new String[] { credentials, "" };
    }/*from   ww w  .  jav  a 2  s .c o m*/
    final String userid = credentials.substring(0, splitIndex);
    final String password = credentials.substring(splitIndex + 1);
    return new String[] { userid, password };
}

From source file:models.service.DefaultFrontendUserService.java

@Override
public FrontendUser authenticate(String mail, String password, String tenant) {
    Logger.info(String.format("Trying to authenticate %s in tenant %s using password ****", mail, tenant));
    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*/

    Tenant validTenant = null;
    for (Tenant tenantInDb : fe.getTenants()) {
        if (tenantInDb.getName().equals(tenant)) {
            validTenant = tenantInDb;
        }
    }

    if (validTenant == null) {
        Logger.info("Authentication failed. User not in tenant.");
        return null;
    }

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

From source file:com.tess4j.rest.Tess4jV1.java

@RequestMapping(value = "ocr/v0.9/upload", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public Status doOcrFile(@RequestBody final Image image) throws Exception {
    File tmpFile = File.createTempFile("ocr_image", image.getExtension());
    try {/*from  w  w  w . j ava2 s .  c  o m*/
        FileUtils.writeByteArrayToFile(tmpFile, Base64.decodeBase64(image.getImage()));
        Tesseract tesseract = Tesseract.getInstance(); // JNA Interface Mapping
        String imageText = tesseract.doOCR(tmpFile);
        LOGGER.info("OCR Image Text = " + imageText);
    } catch (Exception e) {
        LOGGER.error("Exception while converting/uploading image: ", e);
        throw new TesseractException();
    } finally {
        tmpFile.delete();
    }
    return new Status("success");
}

From source file:com.streamsets.lib.security.http.PlainSSOTokenParser.java

@SuppressWarnings("unchecked")
protected SSOUserPrincipal parsePrincipal(String tokenStr, String dataB64) throws IOException {
    SSOUserPrincipalJson principal = null;
    try {/*from   w  w  w. j av  a 2s . c  o m*/
        byte[] data = Base64.decodeBase64(dataB64);
        principal = OBJECT_MAPPER.readValue(data, SSOUserPrincipalJson.class);
        principal.setTokenStr(tokenStr);
        principal.lock();
    } catch (IOException ex) {
        LOG.warn("Could not parse principal payload: {}", ex.toString(), ex);
    }
    return principal;
}

From source file:com.epam.wilma.extras.shortcircuit.ShortCircuitResponseGenerator.java

@Override
public byte[] formatTemplate(WilmaHttpRequest wilmaHttpRequest, HttpServletResponse httpServletResponse,
        byte[] bytes, ParameterList parameterList) throws Exception {
    byte[] newBody;
    //prepare a key for this request
    String hashCode = wilmaHttpRequest.getHeader(ShortCircuitChecker.SHORT_CIRCUIT_HEADER);
    //CHECKSTYLE OFF - we must use "new String" here
    String decodedEntryKey = new String(Base64.decodeBase64(hashCode)); //make it human readable
    //CHECKSTYLE ON
    ShortCircuitResponseInformation shortCircuitResponseInformation = ShortCircuitChecker.getShortCircuitMap()
            .get(hashCode);/*from www .ja va 2s.c  o m*/
    if (shortCircuitResponseInformation != null) {
        //we have the answer, so set it properly
        httpServletResponse.setContentType(shortCircuitResponseInformation.getContentType());
        httpServletResponse.setStatus(shortCircuitResponseInformation.getStatusCode());
        Map<String, String> map = shortCircuitResponseInformation.getHeaders();
        if (map != null) {
            Set<String> keySet = map.keySet();
            for (String key : keySet) {
                httpServletResponse.addHeader(key, map.get(key));
            }
        }
        newBody = shortCircuitResponseInformation.getBody().getBytes();
        shortCircuitResponseInformation.increaseUsageCount(); //hey we just used this cache entry
        logger.info("ShortCircuit: Answer generated for request with hashcode: " + decodedEntryKey);
    } else {
        //this should not happen, we did not find the cached stub answer
        newBody = "Ups, ShortCircuit was unable to find the proper answer, sorry.".getBytes();
        logger.error("ShortCircuit: Response generator did not find proper response for request with code: "
                + decodedEntryKey);
    }
    return newBody;
}

From source file:net.duckling.ddl.service.render.dml.ParseHtmlEmbed.java

public static String getFromBASE64(String s) {
    if (s == null) {
        return null;
    }//from   w w w  . j ava2  s .co  m
    try {
        byte[] b = Base64.decodeBase64(s.getBytes());
        return new String(b);
    } catch (Exception e) {
        return null;
    }
}

From source file:com.splicemachine.derby.stream.output.direct.DirectTableWriterBuilder.java

public static DirectTableWriterBuilder decodeBase64(String base64) {
    byte[] bytes = Base64.decodeBase64(base64);
    return (DirectTableWriterBuilder) SerializationUtils.deserialize(bytes);
}