Example usage for javax.xml.bind DatatypeConverter parseBase64Binary

List of usage examples for javax.xml.bind DatatypeConverter parseBase64Binary

Introduction

In this page you can find the example usage for javax.xml.bind DatatypeConverter parseBase64Binary.

Prototype

public static byte[] parseBase64Binary(String lexicalXSDBase64Binary) 

Source Link

Document

Converts the string argument into an array of bytes.

Usage

From source file:fr.inria.oak.paxquery.pact.operators.unary.PostAggregationOperator.java

@Override
public void open(Configuration parameters) throws Exception {
    super.open(parameters);

    this.aggregationColumn = parameters
            .getInteger(PACTOperatorsConfiguration.POST_AGGREGATION_COLUMN_INT.toString(), -1);

    String aggregationTypeEncoded = parameters
            .getString(PACTOperatorsConfiguration.AGGREGATION_TYPE_BINARY.toString(), null);
    byte[] aggregationTypeBytes = DatatypeConverter.parseBase64Binary(aggregationTypeEncoded);
    final AggregationType aggregationType = (AggregationType) SerializationUtils
            .deserialize(aggregationTypeBytes);
    this.aggregationType = aggregationType;

    this.nestedColumn = parameters.getInteger(PACTOperatorsConfiguration.NESTED_RECORDS_COLUMN_INT.toString(),
            -1);//from w w  w .  j  a v a 2s .c  om

    this.excludeNestedField = parameters
            .getBoolean(PACTOperatorsConfiguration.EXCLUDE_NESTED_FIELD_BOOLEAN.toString(), false);
}

From source file:fr.inria.oak.paxquery.pact.io.XmlConsTreePatternOutputFormat.java

@Override
public void configure(Configuration parameters) {
    super.configure(parameters);

    this.setWriteMode(WriteMode.OVERWRITE);

    // read your own parameters
    String recordsSignatureEncoded = parameters.getString(PACTOperatorsConfiguration.NRSMD1_BINARY.toString(),
            null);// w  w  w .  j a  v a  2  s  .c om
    byte[] recordsSignatureBytes = DatatypeConverter.parseBase64Binary(recordsSignatureEncoded);
    final NestedMetadata signature = (NestedMetadata) SerializationUtils.deserialize(recordsSignatureBytes);
    this.signature = signature;

    String ctpEncoded = parameters.getString(PACTOperatorsConfiguration.CTP_BINARY.toString(), null);
    byte[] ctpBytes = DatatypeConverter.parseBase64Binary(ctpEncoded);
    final ConstructionTreePattern ctp = (ConstructionTreePattern) SerializationUtils.deserialize(ctpBytes);
    this.ctp = ctp;
}

From source file:cz.muni.fi.dndtroopsweb.security.ProtectFilter.java

private String[] parseAuthHeader(String auth) {
    return new String(DatatypeConverter.parseBase64Binary(auth.split(" ")[1])).split(":", 2);
}

From source file:com.mobicage.rogerthat.flow.FormFlowStep.java

public static FormFlowStep fromFormStep(MemberRun run, TextWidgetStep stepDefinition) {
    FormFlowStep step = new FormFlowStep();
    populateFromBaseMessageStep(step, stepDefinition);
    if (FormButton.POSITIVE.equals(stepDefinition.getFormButton())) {
        UnicodeWidgetResult widget = new UnicodeWidgetResult();
        String value = stepDefinition.getValue();
        if (value != null && value.startsWith("base64:"))
            try {
                value = new String(DatatypeConverter.parseBase64Binary(value.substring(7)), "UTF-8");
            } catch (UnsupportedEncodingException e) {
                // do nothing, value will pass with base64: prefix.
            }//from  w  w w  .ja v a  2s .  c  om
        widget.value = value;
        step.result = new FormResult(widget);
    }
    return step;
}

From source file:com.nexmo.client.auth.JWTAuthMethod.java

protected byte[] decodePrivateKey(byte[] data) throws InvalidKeyException {
    try {/*from   ww w.j  av  a2 s.co m*/
        String s = new String(data, "UTF-8");
        Matcher extracter = pemPattern.matcher(s);
        if (extracter.matches()) {
            String pemBody = extracter.group(1);
            return DatatypeConverter.parseBase64Binary(pemBody);
        } else {
            throw new InvalidKeyException("Private key should be provided in PEM format!");
        }
    } catch (UnsupportedEncodingException exc) {
        // This should never happen.
        throw new NexmoUnexpectedException("UTF-8 is an unsupported encoding in this JVM", exc);
    }
}

From source file:com.ddubyat.develop.jhawtcode.util.PropertyUtil.java

private boolean validLicense(String email, String licenseCode) throws Exception {

    Resource res = applicationContext.getResource("classpath:jhc-public.der");
    InputStream is = res.getInputStream();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    byte[] buffer = new byte[4096];
    byte[] pkey;/*from   w ww.jav a  2 s. co m*/
    int stream;
    while ((stream = is.read(buffer, 0, buffer.length)) != -1) {
        baos.write(buffer, 0, stream);
    }

    pkey = baos.toByteArray();

    X509EncodedKeySpec keySpec = new X509EncodedKeySpec(pkey);
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    PublicKey mypk = keyFactory.generatePublic(keySpec);

    Signature instance = Signature.getInstance("SHA1withRSA");
    instance.initVerify(mypk);
    instance.update(email.getBytes());

    //BASE64Decoder decoder = new BASE64Decoder();
    //byte[] decodedBytes = decoder.decodeBuffer(licenseCode);

    return instance.verify(DatatypeConverter.parseBase64Binary(licenseCode));
}

From source file:gobblin.crypto.RotatingAESCodecTest.java

private byte[] readAndBase64DecodeBody(InputStream in) throws IOException {
    byte[] body = IOUtils.toByteArray(in);
    body = DatatypeConverter.parseBase64Binary(new String(body, "UTF-8"));
    return body;//from  w w  w . j av a 2  s.  co  m
}

From source file:io.fabric8.elasticsearch.plugin.auth.FileAuthenticationBackend.java

@Override
public AuthCredentials extractCredentials(RestRequest request, ThreadContext context)
        throws ElasticsearchSecurityException {
    final String authorizationHeader = request.header("Authorization");
    if (authorizationHeader != null) {
        if (authorizationHeader.trim().toLowerCase().startsWith("basic ")) {
            final String decoded = new String(
                    DatatypeConverter.parseBase64Binary(authorizationHeader.split(" ")[1]),
                    StandardCharsets.UTF_8);

            //username:password
            //Assume password is all chars from the last : to the end
            //this is the only way to send service accounts

            final int delimiter = decoded.lastIndexOf(':');

            String username = null;
            String password = null;

            if (delimiter > 0) {
                username = decoded.substring(0, delimiter);

                if (decoded.length() - 1 != delimiter) {
                    password = decoded.substring(delimiter + 1).trim();
                }/*from  ww w  .jav a 2  s  .c  om*/
            }
            if (username != null && StringUtils.isNotEmpty(password)) {
                return new AuthCredentials(username, password.getBytes(StandardCharsets.UTF_8)).markComplete();
            }
        }
    }
    return null;
}

From source file:com.vexsoftware.votifier.util.rsa.RSAIO.java

/**
 * Loads an RSA public key from a URL./*from  w  ww  . j a  v a2s  . com*/
 * 
 * @param url
 *            The URL that has the public key
 * @return
 *            The public key
 * @throws Exception
 *            If an error occurs
 */
public static PublicKey loadPublicKey(URL url) throws Exception {
    String publicKey = new String(IOUtils.toByteArray(url), "UTF-8")
            .replaceAll("(-+BEGIN PUBLIC KEY-+\\r?\\n|-+END PUBLIC KEY-+\\r?\\n?)", "");
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(DatatypeConverter.parseBase64Binary(publicKey));
    return keyFactory.generatePublic(publicKeySpec);
}

From source file:gobblin.crypto.RotatingAESCodecTest.java

private byte[] verifyAndExtractIv(InputStream in, Integer ivLen) throws IOException {
    int bytesRead;
    byte[] base64Iv = new byte[ivLen];
    bytesRead = in.read(base64Iv);/* ww  w .j  a va  2 s  .  c o m*/
    Assert.assertEquals(Integer.valueOf(bytesRead), Integer.valueOf(ivLen), "Expected to read IV");
    return DatatypeConverter.parseBase64Binary(new String(base64Iv, "UTF-8"));
}