[
https://issues.apache.org/jira/browse/CODEC-224?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16074063#comment-16074063
]
ASF GitHub Bot commented on CODEC-224:
--------------------------------------
GitHub user sesuncedu opened a pull request:
https://github.com/apache/commons-codec/pull/7
CODEC-224 Add methods to DigestUtils to generate hex from MessageDigests et
al.
This PR adds methods to DigestUtils to make it easy to generate hexadecimal
strings from:
- MessageDigest,
- DigestInputStream,
- DigestOutputStream.
If the underlying digest supports ```clone()```, a clone is created
before calling ```MessageDigest::digest``` to avoid resetting the state. If
this cannot be done, the original digest is used.
[Although clone is optional for MessageDigests, it seems to be almost
universally supported (e.g. both the Sun and the IBM providers implement clone
for their concrete digests) ]
Signed-off-by: Simon Spero <[email protected]>
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/sesuncedu/commons-codec CODEC-224
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/commons-codec/pull/7.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #7
----
commit e83cea6d26c0a74c4dcca8bc3e04f8ca7a1593b7
Author: Simon Spero <[email protected]>
Date: 2017-07-04T20:15:28Z
Add methods to DigestUtils to generate a hexadecimal string from a
MessageDigest, a DigestInputStream, or a DigestOutputStream. If the underlying
digest implementation implements clone, a clone will be created before
extracting the digest to avoid resetting it.
Signed-off-by: Simon Spero <[email protected]>
----
> Add convenience API
> org.apache.commons.codec.binary.Hex.encodeHexString(byte[]|ByteBuffer,
> boolean)
> ---------------------------------------------------------------------------------------------------
>
> Key: CODEC-224
> URL: https://issues.apache.org/jira/browse/CODEC-224
> Project: Commons Codec
> Issue Type: Improvement
> Reporter: Gary Gregory
> Assignee: Gary Gregory
> Fix For: 1.11
>
>
> Add convenience APIs:
> {{org.apache.commons.codec.binary.Hex.encodeHexString(byte[], boolean)}}:
> {code:java}
> /**
> * Converts an array of bytes into a String representing the hexadecimal
> values of each byte in order. The returned
> * String will be double the length of the passed array, as it takes two
> characters to represent any given byte.
> *
> * @param data
> * a byte[] to convert to Hex characters
> * @param toLowerCase
> * <code>true</code> converts to lowercase, <code>false</code>
> to uppercase
> * @return A String containing lower-case hexadecimal characters
> * @since 1.11
> */
> public static String encodeHexString(final byte[] data, boolean
> toLowerCase)
> {code}
> {{org.apache.commons.codec.binary.Hex.encodeHexString(ByteBuffer, boolean)}}:
> {code:java}
> /**
> * Converts a byte buffer into a String representing the hexadecimal
> values of each byte in order. The returned
> * String will be double the length of the passed array, as it takes two
> characters to represent any given byte.
> *
> * @param data
> * a byte buffer to convert to Hex characters
> * @param toLowerCase
> * <code>true</code> converts to lowercase, <code>false</code>
> to uppercase
> * @return A String containing lower-case hexadecimal characters
> * @since 1.11
> */
> public static String encodeHexString(final ByteBuffer data, boolean
> toLowerCase)
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)