Java code To convert byte to Hexadecimal

后端 未结 19 2449
我寻月下人不归
我寻月下人不归 2020-11-22 17:26

I have an array of bytes. I want each byte String of that array to be converted to its corresponding hexadecimal values.

Is there any function in Java to convert a b

19条回答
  •  余生分开走
    2020-11-22 17:54

    You can use the method from Bouncy Castle Provider library:

    org.bouncycastle.util.encoders.Hex.toHexString(byteArray);
    

    The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms. This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8.

    Maven dependency:

    
        org.bouncycastle
        bcprov-jdk15on
        1.60
    
    

    or from Apache Commons Codec:

    org.apache.commons.codec.binary.Hex.encodeHexString(byteArray);
    

    The Apache Commons Codec package contains simple encoder and decoders for various formats such as Base64 and Hexadecimal. In addition to these widely used encoders and decoders, the codec package also maintains a collection of phonetic encoding utilities.

    Maven dependency:

    
        commons-codec
        commons-codec
        1.11
    
    

提交回复
热议问题