Example usage for org.apache.commons.codec.binary Base64 encodeBase64String

List of usage examples for org.apache.commons.codec.binary Base64 encodeBase64String

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary Base64 encodeBase64String.

Prototype

public static String encodeBase64String(final byte[] binaryData) 

Source Link

Document

Encodes binary data using the base64 algorithm but does not chunk the output.

Usage

From source file:com.cloudera.science.quince.VCFToGA4GHVariantFn.java

public static void configureHeaders(Configuration conf, Path[] vcfs, String sampleGroup) throws IOException {
    List<VCFHeader> headers = new ArrayList<>();
    for (Path vcf : vcfs) {
        InputStream inputStream = vcf.getFileSystem(conf).open(vcf);
        VcfBlockIterator iterator = new VcfBlockIterator(inputStream, new FullVcfCodec());
        VCFHeader header = iterator.getHeader();
        header.addMetaDataLine(new VCFHeaderLine(VARIANT_SET_ID, vcf.getName()));
        headers.add(header);//  www  . jav a  2  s  .  c  o m
    }
    VCFHeader[] headersArray = headers.toArray(new VCFHeader[headers.size()]);
    conf.set(VARIANT_HEADERS, Base64.encodeBase64String(SerializationUtils.serialize(headersArray)));
    if (sampleGroup != null) {
        conf.set(SAMPLE_GROUP, sampleGroup);
    }
}

From source file:com.javaps.springboot.LicenseController.java

@RequestMapping(value = "/public/license", produces = "text/plain", method = RequestMethod.POST)
public String licenseValidate(HttpServletRequest req, @RequestBody String license) throws Exception {
    String clientIp = req.getHeader("X-Forwarded-For"); //nginx???IP
    if (clientIp == null)
        clientIp = req.getRemoteAddr(); //?????
    //System.out.println("clientIp="+clientIp);
    SecretKeySpec signingKey = new SecretKeySpec(licenseSecretKey.getBytes(), "HmacSHA1");
    Mac mac = Mac.getInstance("HmacSHA1");
    mac.init(signingKey);//from ww  w .  j  a  va 2s  .c  om

    byte[] rawHmac = mac.doFinal(clientIp.getBytes());
    //System.out.println("license should be:"+Base64.encodeBase64String(rawHmac));
    if (!license.equals(Base64.encodeBase64String(rawHmac)))
        throw new Exception();

    return "OK";
}

From source file:com.spotify.sshagentproxy.RSA.java

/**
 * Create an {@link RSAPublicKey} from bytes.
 * @param key Array of bytes representing RSA public key.
 * @return {@link RSAPublicKey}//  w ww. j av  a 2  s.c  o  m
 * @throws InvalidKeyException
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeySpecException
 */
static RSAPublicKey from(final byte[] key)
        throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException {

    final String s = new String(key);
    final byte[] encoded;
    final String decoded;
    if (s.startsWith(RSA_LABEL)) {
        decoded = s.split(" ")[1];
        encoded = Base64.decodeBase64(decoded);
    } else {
        encoded = key;
        decoded = Base64.encodeBase64String(key);
    }

    final Iterator<byte[]> fields = new ByteIterator(encoded);
    final String sigType = new String(fields.next());
    if (!sigType.equals(RSA_LABEL)) {
        throw new RuntimeException(String.format("Unknown key type %s. This code currently only supports %s.",
                sigType, RSA_LABEL));
    }

    final RSAPublicKeySpec keySpec = TraditionalKeyParser.parsePemPublicKey(RSA_LABEL + " " + decoded + " ");
    final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    return (RSAPublicKey) keyFactory.generatePublic(keySpec);
}

From source file:biopolis.headless.BiopolisSegmentationManagement.java

public void initialPhase() throws SQLException {
    this.occurs = 0;
    BasicDBObject master = new BasicDBObject();
    master.put("master", "master");
    master.put("biopolisttl", new java.util.Date());
    dbcol.insert(master);/* w  ww.  ja v  a2s . c  om*/
    id = (ObjectId) master.get("_id");
    byte[] bytes = id.toByteArray();
    biopiolisid = Base64.encodeBase64String(bytes);
}

From source file:com.devicehive.service.helpers.DefaultPasswordProcessor.java

@Override
public String generateSalt() {
    byte[] saltBytes = new byte[18]; // .net server uses 18 bytes salt
    secureRandom.nextBytes(saltBytes);//from   ww  w  . j  av  a2 s  .c  o  m
    return Base64.encodeBase64String(saltBytes);
}

From source file:com.consol.citrus.validation.text.BinaryBase64MessageValidatorTest.java

@Test
public void testBinaryBase64Validation() {
    Message receivedMessage = new DefaultMessage("Hello World!".getBytes());
    Message controlMessage = new DefaultMessage(Base64.encodeBase64String("Hello World!".getBytes()));

    ValidationContext validationContext = new DefaultValidationContext();
    validator.validateMessagePayload(receivedMessage, controlMessage, validationContext, context);
}

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

public String sha384(String data) {
    return Base64.encodeBase64String(DigestUtils.sha384(data));
}

From source file:com.mnr.java.intellij.idea.plugin.base64helper.HexEncoderPopupItem.java

@Override
public String encodeDecode(String selectedText) {
    selectedText = Util.makeEvenHexDigit(selectedText);

    byte[] decodeHex;

    try {//from ww  w .j a va  2  s  .co  m
        decodeHex = Hex.decodeHex(selectedText.toCharArray());
    } catch (DecoderException e) {
        e.printStackTrace();
        return null;
    }

    return Base64.encodeBase64String(decodeHex);
}

From source file:eu.europa.esig.dss.Digest.java

@Override
public String toString() {
    return algorithm.getName() + ":" + Base64.encodeBase64String(value);
}

From source file:com.cisco.ca.cstg.pdi.services.license.LicenseCryptoServiceImpl.java

public void setMetaData(String metadata) throws NoSuchAlgorithmException {
    MessageDigest digest = MessageDigest.getInstance(Constants.MD5);

    digest.update(metadata.getBytes(Charset.forName(Constants.UTF8)));

    String b64hash = Base64.encodeBase64String(digest.digest());

    this.metaData = b64hash + ":" + metadata;
}