本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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;
}
示例5: toString
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
@Override
public String toString() {
return "StunAttribute{" +
"type=" + type +
", length=" + length +
", data=" + Hex.encodeHexString(data) +
'}';
}
示例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;
}
示例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);
}
示例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);
}
示例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));
}
示例10: toString
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
@Override
public String toString() {
return "SCTPAttribute{" +
"type=" + type +
", data=" + Hex.encodeHexString(data) +
'}';
}
示例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))
);
}
示例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);
}
示例13: md5Hex
import org.apache.commons.codec.binary.Hex; //导入方法依赖的package包/类
public static String md5Hex(File file) throws FileNotFoundException, IOException {
return Hex.encodeHexString(computeMD5Hash(file));
}
示例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")));
}
示例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()));
}