Example usage for org.apache.commons.codec.binary Hex encodeHexString

List of usage examples for org.apache.commons.codec.binary Hex encodeHexString

Introduction

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

Prototype

public static String encodeHexString(byte[] data) 

Source Link

Document

Converts an array of bytes into a String representing the hexadecimal values of each byte in order.

Usage

From source file:com.google.u2f.key.impl.U2FKeyReferenceImpl.java

@Override
public RegisterResponse register(RegisterRequest registerRequest) throws U2FException {
    Log.info(">> register");

    byte[] applicationSha256 = registerRequest.getApplicationSha256();
    byte[] challengeSha256 = registerRequest.getChallengeSha256();

    Log.info(" -- Inputs --");
    Log.info("  applicationSha256: " + Hex.encodeHexString(applicationSha256));
    Log.info("  challengeSha256: " + Hex.encodeHexString(challengeSha256));

    byte userPresent = userPresenceVerifier.verifyUserPresence();
    if ((userPresent & UserPresenceVerifier.USER_PRESENT_FLAG) == 0) {
        throw new U2FException("Cannot verify user presence");
    }/*from w  ww  .j  av a 2 s.com*/

    KeyPair keyPair = keyPairGenerator.generateKeyPair(applicationSha256, challengeSha256);
    byte[] keyHandle = keyHandleGenerator.generateKeyHandle(applicationSha256, keyPair);

    dataStore.storeKeyPair(keyHandle, keyPair);

    byte[] userPublicKey = keyPairGenerator.encodePublicKey(keyPair.getPublic());

    byte[] signedData = RawMessageCodec.encodeRegistrationSignedBytes(applicationSha256, challengeSha256,
            keyHandle, userPublicKey);
    Log.info("Signing bytes " + Hex.encodeHexString(signedData));

    byte[] signature = crypto.sign(signedData, certificatePrivateKey);

    Log.info(" -- Outputs --");
    Log.info("  userPublicKey: " + Hex.encodeHexString(userPublicKey));
    Log.info("  keyHandle: " + Hex.encodeHexString(keyHandle));
    Log.info("  vendorCertificate: " + vendorCertificate);
    Log.info("  signature: " + Hex.encodeHexString(signature));

    Log.info("<< register");

    return new RegisterResponse(userPublicKey, keyHandle, vendorCertificate, signature);
}

From source file:com.playonlinux.utils.cab.CFFolder.java

public void dump() {
    System.out.println(Hex.encodeHexString(coffCabStart));
    System.out.println(Hex.encodeHexString(cCFData));
    System.out.println(Hex.encodeHexString(typeCompress));

    System.out.println(this);
}

From source file:com.lightboxtechnologies.nsrl.HashData.java

@Override
public String toString() {
    return String.format(
            "%s[sha1=\"%s\",md5=\"%s\",crc32=\"%s\",name=\"%s\",size=%d,prod_code=%d,os_code=\"%s\",special_code=\"%s\"]",
            getClass().getName(), Hex.encodeHexString(sha1), Hex.encodeHexString(md5),
            Hex.encodeHexString(crc32), name, size, prod_code, os_code, special_code);
}

From source file:internal.diff.aws.service.AmazonS3ETagFileChecksumServiceImpl.java

@Override
public String calculateChecksum(Path file) throws IOException {

    long fileSize = Files.size(file);

    int parts = (int) (fileSize / S3_MULTIPART_SIZE_LIMIT_IN_BYTES);
    parts += fileSize % S3_MULTIPART_SIZE_LIMIT_IN_BYTES > 0 ? 1 : 0;

    ByteBuffer checksumBuffer = ByteBuffer.allocate(parts * 16);

    SeekableByteChannel byteChannel = Files.newByteChannel(file);

    for (int part = 0; part < parts; part++) {

        int partSizeInBytes;

        if (part < parts - 1 || fileSize % S3_MULTIPART_SIZE_LIMIT_IN_BYTES == 0) {
            partSizeInBytes = S3_MULTIPART_SIZE_LIMIT_IN_BYTES;
        } else {//  w ww  . j ava2s. c om
            partSizeInBytes = (int) (fileSize % S3_MULTIPART_SIZE_LIMIT_IN_BYTES);
        }

        ByteBuffer partBuffer = ByteBuffer.allocate(partSizeInBytes);

        boolean endOfFile;
        do {
            endOfFile = byteChannel.read(partBuffer) == -1;
        } while (!endOfFile && partBuffer.hasRemaining());

        checksumBuffer.put(DigestUtils.md5(partBuffer.array()));
    }

    if (parts > 1) {
        return DigestUtils.md5Hex(checksumBuffer.array()) + "-" + parts;
    } else {
        return Hex.encodeHexString(checksumBuffer.array());
    }
}

From source file:it.scoppelletti.security.keygen.DESKeyToPropertySetProvider.java

public Properties toProperties(Key key) {
    byte[] data;/*from  w w w .  j  a  v a2  s .co  m*/
    SecretKey desKey;
    SecretKeyFactory keyFactory;
    DESKeySpec param;
    Properties props;

    if (!(key instanceof SecretKey)) {
        return null;
    }

    try {
        keyFactory = SecretKeyFactory.getInstance(DESKeyFactory.ALGORITHM);
    } catch (NoSuchAlgorithmException ex) {
        return null;
    }

    try {
        desKey = keyFactory.translateKey((SecretKey) key);
    } catch (InvalidKeyException ex) {
        return null;
    }

    try {
        param = (DESKeySpec) keyFactory.getKeySpec(desKey, DESKeySpec.class);
    } catch (InvalidKeySpecException ex) {
        return null;
    }

    props = new Properties();
    props.setProperty(CryptoUtils.PROP_KEYFACTORY, DESKeyFactory.class.getName());
    data = param.getKey();
    props.setProperty(DESKeyFactory.PROP_KEY, Hex.encodeHexString(data));
    Arrays.fill(data, Byte.MIN_VALUE);

    return props;
}

From source file:net.mooncloud.hadoop.hive.ql.udf.UDFMd5.java

/**
 * Convert bytes to md5//w w w. jav a  2s  .  co m
 */
public Text evaluate(BytesWritable b) {
    if (b == null) {
        return null;
    }

    digest.reset();
    digest.update(b.getBytes(), 0, b.getLength());
    byte[] md5Bytes = digest.digest();
    String md5Hex = Hex.encodeHexString(md5Bytes);

    result.set(md5Hex);
    return result;
}

From source file:inti.ws.spring.resource.ByteWebResource.java

/**
 * Reads the file and stores it's content.
 *///from www  . j  a v  a  2  s  .  com
@Override
public void update() throws Exception {
    StringBuilder builder = new StringBuilder(32);
    MessageDigest digest = DIGESTS.get();
    InputStream inputStream = resource.getInputStream();

    try {
        lastModified = resource.lastModified();
        bytes = IOUtils.toByteArray(inputStream);
    } finally {
        inputStream.close();
    }

    digest.reset();
    builder.append(Hex.encodeHexString(digest.digest(bytes)));
    messageDigest = builder.toString();
    builder.delete(0, builder.length());

    DATE_FORMATTER.formatDate(lastModified, builder);
    lastModifiedString = builder.toString();
}

From source file:net.solarnetwork.node.rfxcom.test.CommandMessageTest.java

@Test
public void encodeStatusCommand() {
    CommandMessage msg = new CommandMessage(Command.Status, (short) 1);
    assertNull("Data", msg.getData());
    final byte[] packet = msg.getMessagePacket();
    log.debug("Got packet: " + Hex.encodeHexString(packet));
    assertNotNull("Packet", packet);
    assertArrayEquals(TestUtils.bytesFromHexString("0D 00 00 01 02 00 00 00 00 00 00 00 00 00"), packet);
}

From source file:it.scoppelletti.security.keygen.DESedeKeyToPropertySetProvider.java

public Properties toProperties(Key key) {
    byte[] data;//  ww  w. jav a  2  s.  c o m
    SecretKey desKey;
    SecretKeyFactory keyFactory;
    DESedeKeySpec param;
    Properties props;

    if (!(key instanceof SecretKey)) {
        return null;
    }

    try {
        keyFactory = SecretKeyFactory.getInstance(DESedeKeyFactory.ALGORITHM);
    } catch (NoSuchAlgorithmException ex) {
        return null;
    }

    try {
        desKey = keyFactory.translateKey((SecretKey) key);
    } catch (InvalidKeyException ex) {
        return null;
    }

    try {
        param = (DESedeKeySpec) keyFactory.getKeySpec(desKey, DESedeKeySpec.class);
    } catch (InvalidKeySpecException ex) {
        return null;
    }

    props = new Properties();
    props.setProperty(CryptoUtils.PROP_KEYFACTORY, DESedeKeyFactory.class.getName());
    data = param.getKey();
    props.setProperty(DESedeKeyFactory.PROP_KEY, Hex.encodeHexString(data));
    Arrays.fill(data, Byte.MIN_VALUE);

    return props;
}

From source file:com.github.horrorho.inflatabledonkey.requests.AuthorizeGetRequestFactory.java

public Optional<HttpUriRequest> newRequest(String dsPrsID, String contentBaseUrl, String container, String zone,
        CloudKit.FileTokens fileTokens) {

    if (fileTokens.getFileTokensCount() == 0) {
        return Optional.empty();
    }//from  w ww . j  a v a 2 s. com

    CloudKit.FileToken base = fileTokens.getFileTokens(0);

    String mmcsAuthToken = Stream
            .of(Hex.encodeHexString(base.getFileChecksum().toByteArray()),
                    Hex.encodeHexString(base.getFileSignature().toByteArray()), base.getToken())
            .collect(Collectors.joining(" "));

    ByteArrayEntity byteArrayEntity = new ByteArrayEntity(fileTokens.toByteArray());

    String uri = contentBaseUrl + "/" + dsPrsID + "/authorizeGet";

    HttpUriRequest request = RequestBuilder.post(uri)
            .addHeader(Headers.ACCEPT.header("application/vnd.com.apple.me.ubchunk+protobuf"))
            .addHeader(Headers.CONTENTTYPE.header("application/vnd.com.apple.me.ubchunk+protobuf"))
            .addHeader(Headers.XAPPLEMMCSDATACLASS.header("com.apple.Dataclass.CloudKit"))
            .addHeader(Headers.XAPPLEMMCSAUTH.header(mmcsAuthToken))
            .addHeader(Headers.XAPPLEMMEDSID.header(dsPrsID))
            .addHeader(Headers.XCLOUDKITCONTAINER.header(container))
            .addHeader(Headers.XCLOUDKITZONES.header(zone)).addHeader(headers.get(Headers.USERAGENT))
            .addHeader(headers.get(Headers.XAPPLEMMCSPROTOVERSION))
            .addHeader(headers.get(Headers.XMMECLIENTINFO)).setEntity(byteArrayEntity).build();

    return Optional.of(request);
}