org.apache.commons.codec.binary.Hex.encodeHexString()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(200)

本文整理了Java中org.apache.commons.codec.binary.Hex.encodeHexString()方法的一些代码示例,展示了Hex.encodeHexString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hex.encodeHexString()方法的具体详情如下:
包路径:org.apache.commons.codec.binary.Hex
类名称:Hex
方法名:encodeHexString

Hex.encodeHexString介绍

[英]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.
[中]

代码示例

代码示例来源:origin: jenkinsci/jenkins

/**
 * Utility method supporting both possible digest formats: Base64 and Hex
 */
private boolean digestMatches(byte[] digest, String providedDigest) {
  return providedDigest.equalsIgnoreCase(Hex.encodeHexString(digest)) || providedDigest.equalsIgnoreCase(new String(Base64.encode(digest)));
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * Returns the digest for the file.
 *
 * @param valueToDigest the file to use
 * @return the digest as a hex String
 * @throws IOException
 *             If an I/O error occurs.
 * @since 1.11
 */
public String hmacHex(final File valueToDigest) throws IOException {
  return Hex.encodeHexString(hmac(valueToDigest));
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * Reads through a ByteBuffer and returns the digest for the data
 *
 * @param data
 *            Data to digest
 * @return the digest as a hex string
 *
 * @since 1.11
 */
public String digestAsHex(final ByteBuffer data) {
  return Hex.encodeHexString(digest(data));
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * Calculates the SHA-1 digest and returns the value as a hex string.
 *
 * @param data
 *            Data to digest
 * @return SHA-1 digest as a hex string
 * @since 1.7
 */
public static String sha1Hex(final byte[] data) {
  return Hex.encodeHexString(sha1(data));
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * Returns the digest for the input data.
 *
 * @param valueToDigest the input to use
 * @return the digest as a hex String
 * @since 1.11
 */
public String hmacHex(final byte[] valueToDigest) {
  return Hex.encodeHexString(hmac(valueToDigest));
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * Calculates the MD5 digest and returns the value as a 32 character hex string.
 *
 * @param data
 *            Data to digest
 * @return MD5 digest as a hex string
 */
public static String md5Hex(final byte[] data) {
  return Hex.encodeHexString(md5(data));
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * Calculates the MD5 digest and returns the value as a 32 character hex string.
 *
 * @param data
 *            Data to digest
 * @return MD5 digest as a hex string
 */
public static String md5Hex(final String data) {
  return Hex.encodeHexString(md5(data));
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * Reads through a byte array and returns the digest for the data.
 *
 * @param data
 *            Data to digest
 * @return the digest as a hex string
 * @since 1.11
 */
public String digestAsHex(final byte[] data) {
  return Hex.encodeHexString(digest(data));
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * Reads through a byte array and returns the digest for the data.
 *
 * @param data
 *            Data to digest treated as UTF-8 string
 * @return the digest as a hex string
 * @since 1.11
 */
public String digestAsHex(final String data) {
  return Hex.encodeHexString(digest(data));
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * Returns the digest for the input data.
 *
 * @param valueToDigest the input to use, treated as UTF-8
 * @return the digest as a hex String
 * @since 1.11
 */
public String hmacHex(final String valueToDigest) {
  return Hex.encodeHexString(hmac(valueToDigest));
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * Returns the digest for the input data.
 *
 * @param valueToDigest the input to use
 * @return the digest as a hex String
 * @since 1.11
 */
public String hmacHex(final ByteBuffer valueToDigest) {
  return Hex.encodeHexString(hmac(valueToDigest));
}

代码示例来源:origin: commons-codec/commons-codec

private void println(final String prefix, final byte[] digest, final String fileName) {
  // The standard appears to be to print
  // hex, space, then either space or '*' followed by filename
  // where '*' is used for binary files
  // shasum(1) has a -b option which generates " *" separator
  // we don't distinguish binary files at present
  System.out.println(prefix + Hex.encodeHexString(digest) + (fileName != null ? "  " + fileName : ""));
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * Calculates the MD2 digest and returns the value as a 32 character hex string.
 *
 * @param data
 *            Data to digest
 * @return MD2 digest as a hex string
 * @since 1.7
 */
public static String md2Hex(final byte[] data) {
  return Hex.encodeHexString(md2(data));
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * Calculates the SHA-1 digest and returns the value as a hex string.
 *
 * @param data
 *            Data to digest
 * @return SHA-1 digest as a hex string
 * @since 1.7
 */
public static String sha1Hex(final String data) {
  return Hex.encodeHexString(sha1(data));
}

代码示例来源:origin: commons-codec/commons-codec

/**
 * Calculates the MD2 digest and returns the value as a 32 character hex string.
 *
 * @param data
 *            Data to digest
 * @return MD2 digest as a hex string
 * @since 1.7
 */
public static String md2Hex(final String data) {
  return Hex.encodeHexString(md2(data));
}

代码示例来源:origin: commons-codec/commons-codec

@Test
public void testEncodeHexByteString_ByteBufferOfZeroes() {
  final String c = Hex.encodeHexString(ByteBuffer.allocate(36));
  assertEquals("000000000000000000000000000000000000000000000000000000000000000000000000", c);
}

代码示例来源:origin: commons-codec/commons-codec

@Test
public void testHmacSha1UpdateWithInpustream() throws IOException {
  final Mac mac = HmacUtils.getHmacSha1(HmacAlgorithmsTest.STANDARD_KEY_BYTES);
  HmacUtils.updateHmac(mac, new ByteArrayInputStream(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES));
  assertEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_STRING, Hex.encodeHexString(mac.doFinal()));
  HmacUtils.updateHmac(mac, new ByteArrayInputStream("".getBytes()));
  assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", Hex.encodeHexString(mac.doFinal()));
}

代码示例来源:origin: commons-codec/commons-codec

@Test
public void testEncodeHexByteString_ByteArrayOfZeroes() {
  final String c = Hex.encodeHexString(new byte[36]);
  assertEquals("000000000000000000000000000000000000000000000000000000000000000000000000", c);
}

代码示例来源:origin: commons-codec/commons-codec

@Test
public void testHmacSha1UpdateWithByteArray() throws IOException {
  final Mac mac = HmacUtils.getHmacSha1(HmacAlgorithmsTest.STANDARD_KEY_BYTES);
  HmacUtils.updateHmac(mac, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES);
  assertEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_STRING, Hex.encodeHexString(mac.doFinal()));
  HmacUtils.updateHmac(mac, "".getBytes());
  assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", Hex.encodeHexString(mac.doFinal()));
}

代码示例来源:origin: commons-codec/commons-codec

@Test
public void testHmacSha1UpdateWithString() throws IOException {
  final Mac mac = HmacUtils.getHmacSha1(HmacAlgorithmsTest.STANDARD_KEY_BYTES);
  HmacUtils.updateHmac(mac, HmacAlgorithmsTest.STANDARD_PHRASE_STRING);
  assertEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_STRING, Hex.encodeHexString(mac.doFinal()));
  HmacUtils.updateHmac(mac, "");
  assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", Hex.encodeHexString(mac.doFinal()));
}

相关文章