当前位置: 首页>>代码示例>>Java>>正文


Java Hex.encodeHexString方法代码示例

本文整理汇总了Java中org.apache.commons.codec.binary.Hex.encodeHexString方法的典型用法代码示例。如果您正苦于以下问题:Java Hex.encodeHexString方法的具体用法?Java Hex.encodeHexString怎么用?Java Hex.encodeHexString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.codec.binary.Hex的用法示例。


在下文中一共展示了Hex.encodeHexString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getStringFromList

import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
private String getStringFromList(List<byte[]> listOfBytes, int offset) {
  String value1;
  if (listOfBytes.size() > offset) {
    value1 = Hex.encodeHexString(listOfBytes.get(offset));
  } else {
    value1 = "<missing>";
  }
  return value1;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:10,代码来源:TestScanRowPrefix.java

示例2: onBlock

import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
/**
 * does something on a "block" message.
 *
 * @param peer
 *            the peer that sent the message.
 * @param message
 *            the message.
 */
private void onBlock(final RemoteNodeControllerRunnable peer, final Message message) {
	if (stopped) {
		return;
	}
	final Block newBlock = message.getPayload(Block.class);

	final String expected = new String(Hex.encodeHexString(message.getPayloadByteArray()));
	final String actual = Hex.encodeHexString(newBlock.toByteArray());

	if (!expected.equals(actual)) {
		LOG.error("onBlock newBlock: {}", newBlock);
		LOG.error("onBlock expected: {}", expected);
		LOG.error("onBlock actual  : {}", actual);
		return;
	}

	LocalNodeDataSynchronizedUtil.addUnverifiedBlock(localNodeData, newBlock);
	// LocalNodeDataSynchronizedUtil.verifyUnverifiedBlocks(localNodeData);
}
 
开发者ID:coranos,项目名称:neo-java,代码行数:28,代码来源:LocalControllerNode.java

示例3: evaluate

import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
/**
 * Convert bytes to md5
 */
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;
}
 
开发者ID:myui,项目名称:hive-udf-backports,代码行数:17,代码来源:UDFMd5.java

示例4: getGravatarImg

import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
/**
 * Generates the gravatar image URL for the given {@link User}.
 * It generates a MD5 hash of the user's email and prefixes and postfixes it with
 * {@link #URL_PREFIX} and {@link #URL_POSTFIX}.
 * @param user the {@link User} to generate the image.
 * @return the generated gravatar image URL
 */
public static String getGravatarImg(final User user) {
	ObjectUtil.assertNotNull(user, "user may not be null");
	ObjectUtil.assertNotNull(user.getEmail(), "email of user may not be null");

	try {
		final MessageDigest md5 = MessageDigest.getInstance("MD5");
		final byte[] mailHash = md5.digest(user.getEmail().toLowerCase().getBytes());
		return URL_PREFIX + Hex.encodeHexString(mailHash) + URL_POSTFIX;
	} catch (final NoSuchAlgorithmException e) {
		LOGGER.error("Can't generate gravatar image url because md5 algorithm was not found.", e);
	}

	return null;
}
 
开发者ID:XMBomb,项目名称:InComb,代码行数:22,代码来源:GravatarUtil.java

示例5: toString

import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
@Override
public String toString() {
    return "StunAttribute{" +
            "type=" + type +
            ", length=" + length +
            ", data=" + Hex.encodeHexString(data) +
            '}';
}
 
开发者ID:IIlllII,项目名称:bitbreeds-webrtc,代码行数:9,代码来源:StunAttribute.java

示例6: encode

import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
@Override
public String encode(final CharSequence password) {
    if (password == null) {
        return null;
    }

    if (StringUtils.isBlank(this.encodingAlgorithm)) {
        LOGGER.warn("No encoding algorithm is defined. Password cannot be encoded; Returning null");
        return null;
    }

    final String encodingCharToUse = StringUtils.isNotBlank(this.characterEncoding)
            ? this.characterEncoding : Charset.defaultCharset().name();

    LOGGER.debug("Using [{}] as the character encoding algorithm to update the digest", encodingCharToUse);

    try {
        final byte[] pswBytes = password.toString().getBytes(encodingCharToUse);
        final String encoded = Hex.encodeHexString(DigestUtils.getDigest(this.encodingAlgorithm).digest(pswBytes));
        LOGGER.debug("Encoded password via algorithm [{}] and character-encoding [{}] is [{}]", this.encodingAlgorithm,
                encodingCharToUse, encoded);
        return encoded;
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:28,代码来源:DefaultPasswordEncoder.java

示例7: getNonce

import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
/**
 * Get the nonce of the account
 * @param httpAgent the HTTP agent used to get the nonce from a running peer via the RPC
 * @return the nonce in BigInteger
 * @throws IOException
 */
private BigInteger getNonce(Http httpAgent) throws IOException{
   	String queryNonceString="{\"method\":\"parity_nextNonce\",\"params\":[\"0x"+Hex.encodeHexString(ecKeyPair.getAddress())+"\"],\"id\":42,\"jsonrpc\":\"2.0\"}";
   	String myNonceResult="";
   	try {
   		myNonceResult=(String)httpAgent.getHttpResponse(queryNonceString);
       }catch (IOException e) {
       	throw e;
       }
	return new BigInteger(myNonceResult.substring(2),16);
}
 
开发者ID:RightMesh,项目名称:microraiden-java,代码行数:17,代码来源:Wallet.java

示例8: getEtherBalance

import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
/**
 * Get the balance of ether on the Ethereum network.
 * @param httpAgent the HTTP agent used to get the Ether balance from a running peer via the RPC
 * @return the Ether balance in BigInteger
 * @throws IOException
 */
private BigInteger getEtherBalance(Http httpAgent) throws IOException{
	String queryEtherBalanceString="{\"method\":\"eth_getBalance\",\"params\":[\"0x"+Hex.encodeHexString(ecKeyPair.getAddress())+"\"],\"id\":42,\"jsonrpc\":\"2.0\"}";
       //System.out.println("The request string in getEtherBalance is "+requestString);
       String myEtherBalance="";
   	try {
   		myEtherBalance=(String)httpAgent.getHttpResponse(queryEtherBalanceString);
       }catch (IOException e) {
       	throw e;
       }
   	return new BigInteger(myEtherBalance.substring(2),16);
}
 
开发者ID:RightMesh,项目名称:microraiden-java,代码行数:18,代码来源:Wallet.java

示例9: multipleInstancesTest

import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
@Test
public void multipleInstancesTest() throws InterruptedException {
    final Set<String> ids = Collections.synchronizedSet(new HashSet<String>());
    final int threadCount = 20;
    final int iterationCount = 10000;
    final CountDownLatch latch = new CountDownLatch(threadCount);

    for (int i = 0; i < threadCount; i++) {
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                IDGenerator generator = LocalUniqueIDGeneratorFactory.generatorFor(1, 1);
                try {
                    for (int i = 0; i < iterationCount; i++) {
                        byte[] id = generator.generate();
                        String asHex = Hex.encodeHexString(id);
                        ids.add(asHex);
                    }
                } catch (GeneratorException e) {
                    e.printStackTrace();
                }
                latch.countDown();
            }
        });
        t.start();
    }

    boolean successfullyUnlatched = latch.await(20, TimeUnit.SECONDS);
    assertThat(successfullyUnlatched, is(true));

    assertThat(ids.size(), is(threadCount * iterationCount));
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:33,代码来源:UniqueIDGeneratorThreadSafetyIT.java

示例10: toString

import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
@Override
public String toString() {
    return "SCTPAttribute{" +
            "type=" + type +
            ", data=" + Hex.encodeHexString(data) +
            '}';
}
 
开发者ID:IIlllII,项目名称:bitbreeds-webrtc,代码行数:8,代码来源:SCTPAttribute.java

示例11: fromBytes

import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
public static SCTPHeader fromBytes(byte[] bytes) {
    if(bytes.length != 12) {
        throw new IllegalArgumentException("Bytes given are incorrect length to be an SCTP header: "
                + " length: " + bytes.length + "  data:" + Hex.encodeHexString(bytes));
    }
    return new SCTPHeader(
            SignalUtil.intFromTwoBytes(Arrays.copyOf(bytes,2)),
            SignalUtil.intFromTwoBytes(Arrays.copyOfRange(bytes,2,4)),
            SignalUtil.bytesToLong(Arrays.copyOfRange(bytes,4,8)),
            SignalUtil.bytesToLong(Arrays.copyOfRange(bytes,8,12))
    );
}
 
开发者ID:IIlllII,项目名称:bitbreeds-webrtc,代码行数:13,代码来源:SCTPHeader.java

示例12: toHex

import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
public static String toHex(byte[] value) {
    if (value == null) {
        return null;
    }
    return Hex.encodeHexString(value);
}
 
开发者ID:ARMmbed,项目名称:mbed-cloud-sdk-java,代码行数:7,代码来源:HexArray.java

示例13: md5Hex

import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
public static String md5Hex(File file) throws FileNotFoundException, IOException {
    return Hex.encodeHexString(computeMD5Hash(file));
}
 
开发者ID:tencentyun,项目名称:cos-java-sdk-v5,代码行数:4,代码来源:Md5Utils.java

示例14: hmacEncode

import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
public static String hmacEncode(String key, String data) throws Exception {
    Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
    SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");
    sha256_HMAC.init(secret_key);
    return Hex.encodeHexString(sha256_HMAC.doFinal(data.getBytes("UTF-8")));
}
 
开发者ID:wcrbrm,项目名称:java-coinexchange-api,代码行数:7,代码来源:CoinexchangeRequest.java

示例15: test

import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
private static void test(String input, String expected) throws DecoderException {
    byte[] bytes = HashUtil.sha3(Hex.decodeHex(input));
    String result = Hex.encodeHexString(bytes);
    Assert.assertTrue(Arrays.equals(expected.getBytes(), result.getBytes()));
}
 
开发者ID:fergarrui,项目名称:ethereum-bytecode-analyzer,代码行数:6,代码来源:HashTest.java


注:本文中的org.apache.commons.codec.binary.Hex.encodeHexString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。