Java Hex Calculate toHexString(byte[] digest)

Here you can find the source of toHexString(byte[] digest)

Description

to Hex String

License

Open Source License

Declaration

public static String toHexString(byte[] digest) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 Sonatype, Inc./*from  w  ww  .  j a v  a 2 s  .c  o m*/
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 *   http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

public class Main {
    public static String toHexString(byte[] digest) {
        String chars = "0123456789abcdef";
        StringBuilder buffer = new StringBuilder(digest.length * 2);
        for (int i = 0; i < digest.length; i++) {
            int b = digest[i] & 0xFF;
            buffer.append(chars.charAt(b >> 4));
            buffer.append(chars.charAt(b & 0xF));
        }
        return buffer.toString();
    }
}

Related

  1. toHexString(byte[] data, int offset, int length)
  2. toHexString(byte[] data, int offset, int length)
  3. toHexString(byte[] data, int start, int len)
  4. toHexString(byte[] data, int start, int length)
  5. toHexString(byte[] digest)
  6. toHexString(byte[] digest)
  7. toHexString(byte[] digestByte)
  8. toHexString(byte[] in)
  9. toHexString(byte[] input)