org.spongycastle.util.encoders.Hex.encode()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(173)

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

Hex.encode介绍

[英]encode the input data producing a Hex encoded byte array.
[中]对输入数据进行编码,生成十六进制编码的字节数组。

代码示例

代码示例来源:origin: ethereum/ethereumj

public static byte[] binToNibblesNoTerminator(byte[] str) {

    byte[] hexEncoded = encode(str);

    for (int i = 0; i < hexEncoded.length; ++i){
      byte b = hexEncoded[i];
      hexEncoded[i] = hexMap.get((char) b);
    }

    return hexEncoded;
  }
}

代码示例来源:origin: ethereum/ethereumj

/**
 * Transforms a binary array to hexadecimal format + terminator
 *
 * @param str byte[]
 * @return array with each individual nibble adding a terminator at the end
 */
public static byte[] binToNibbles(byte[] str) {
  byte[] hexEncoded = encode(str);
  byte[] hexEncodedTerminated = Arrays.copyOf(hexEncoded, hexEncoded.length + 1);
  for (int i = 0; i < hexEncoded.length; ++i){
    byte b = hexEncodedTerminated[i];
    hexEncodedTerminated[i] = hexMap.get((char) b);
  }
  hexEncodedTerminated[hexEncodedTerminated.length - 1] = TERMINATOR;
  return hexEncodedTerminated;
}

代码示例来源:origin: ethereum/ethereumj

@Test
public void testAddressStringToBytes() {
  // valid address
  String HexStr = "6c386a4b26f73c802f34673f7248bb118f97424a";
  byte[] expected = Hex.decode(HexStr);
  byte[] result = Utils.addressStringToBytes(HexStr);
  assertEquals(Arrays.areEqual(expected, result), true);
  // invalid address, we removed the last char so it cannot decode
  HexStr = "6c386a4b26f73c802f34673f7248bb118f97424";
  expected = null;
  result = Utils.addressStringToBytes(HexStr);
  assertEquals(expected, result);
  // invalid address, longer than 20 bytes
  HexStr = new String(Hex.encode("I am longer than 20 bytes, i promise".getBytes()));
  expected = null;
  result = Utils.addressStringToBytes(HexStr);
  assertEquals(expected, result);
  // invalid address, shorter than 20 bytes
  HexStr = new String(Hex.encode("I am short".getBytes()));
  expected = null;
  result = Utils.addressStringToBytes(HexStr);
  assertEquals(expected, result);
}

代码示例来源:origin: com.madgag/sc-light-jdk15on

/**
 * encode the input data producing a Hex encoded byte array.
 *
 * @return a byte array containing the Hex encoded data.
 */
public static byte[] encode(
  byte[]    data)
{
  return encode(data, 0, data.length);
}

代码示例来源:origin: com.madgag.spongycastle/core

/**
 * encode the input data producing a Hex encoded byte array.
 *
 * @return a byte array containing the Hex encoded data.
 */
public static byte[] encode(
  byte[]    data)
{
  return encode(data, 0, data.length);
}

代码示例来源:origin: nuls-io/nuls

public static byte[] binToNibblesNoTerminator(byte[] str) {

    byte[] hexEncoded = encode(str);

    for (int i = 0; i < hexEncoded.length; ++i) {
      byte b = hexEncoded[i];
      hexEncoded[i] = hexMap.get((char) b);
    }

    return hexEncoded;
  }
}

代码示例来源:origin: QuincySx/BlockchainWallet-Crypto

public static byte[] binToNibblesNoTerminator(byte[] str) {

    byte[] hexEncoded = encode(str);

    for (int i = 0; i < hexEncoded.length; ++i) {
      byte b = hexEncoded[i];
      hexEncoded[i] = hexMap.get((char) b);
    }

    return hexEncoded;
  }
}

代码示例来源:origin: AppStoreFoundation/asf-sdk

public static byte[] binToNibblesNoTerminator(byte[] str) {

  byte[] hexEncoded = encode(str);

  for (int i = 0; i < hexEncoded.length; ++i) {
   byte b = hexEncoded[i];
   hexEncoded[i] = hexMap.get((char) b);
  }

  return hexEncoded;
 }
}

代码示例来源:origin: com.madgag/sc-light-jdk15on

public String toString()
  {
   return "#"+new String(Hex.encode(string));
  }
}

代码示例来源:origin: biheBlockChain/wkcwallet-java

public static byte[] binToNibblesNoTerminator(byte[] str) {

    byte[] hexEncoded = encode(str);

    for (int i = 0; i < hexEncoded.length; ++i){
      byte b = hexEncoded[i];
      hexEncoded[i] = hexMap.get((char) b);
    }

    return hexEncoded;
  }
}

代码示例来源:origin: blockchain/unused-My-Wallet-V3-jar

@Override
public String toString() {
  if (hash == null)
    return null;
  return new String(Hex.encode(hash));
}

代码示例来源:origin: nuls-io/nuls

/**
 * Transforms a binary array to hexadecimal format + terminator
 *
 * @param str byte[]
 * @return array with each individual nibble adding a terminator at the end
 */
public static byte[] binToNibbles(byte[] str) {
  byte[] hexEncoded = encode(str);
  byte[] hexEncodedTerminated = Arrays.copyOf(hexEncoded, hexEncoded.length + 1);
  for (int i = 0; i < hexEncoded.length; ++i) {
    byte b = hexEncodedTerminated[i];
    hexEncodedTerminated[i] = hexMap.get((char) b);
  }
  hexEncodedTerminated[hexEncodedTerminated.length - 1] = TERMINATOR;
  return hexEncodedTerminated;
}

代码示例来源:origin: QuincySx/BlockchainWallet-Crypto

/**
 * Transforms a binary array to hexadecimal format + terminator
 *
 * @param str byte[]
 * @return array with each individual nibble adding a terminator at the end
 */
public static byte[] binToNibbles(byte[] str) {
  byte[] hexEncoded = encode(str);
  byte[] hexEncodedTerminated = Arrays.copyOf(hexEncoded, hexEncoded.length + 1);
  for (int i = 0; i < hexEncoded.length; ++i) {
    byte b = hexEncodedTerminated[i];
    hexEncodedTerminated[i] = hexMap.get((char) b);
  }
  hexEncodedTerminated[hexEncodedTerminated.length - 1] = TERMINATOR;
  return hexEncodedTerminated;
}

代码示例来源:origin: com.madgag.spongycastle/core

public String toString()
  {
   return "#"+ Strings.fromByteArray(Hex.encode(string));
  }
}

代码示例来源:origin: com.google/bitcoinj

@Override
  public String toString() {
    return MessageFormat.format("ExtendedHierarchicKey[pub: {0}]", new String(Hex.encode(getPubKeyBytes())));
  }
}

代码示例来源:origin: lhalcyon/dapp-wallet-demo

public String getPrivateKey(){
  return new String(Hex.encode(getKey()));
}

代码示例来源:origin: lhalcyon/dapp-wallet-demo

public String getPublicKey(){
    return new String(Hex.encode(getKey()));
  }
}

代码示例来源:origin: com.madgag.spongycastle/core

public static String toHexString(
  byte[] data,
  int    off,
  int    length)
{
  byte[] encoded = encode(data, off, length);
  return Strings.fromByteArray(encoded);
}

代码示例来源:origin: blockchain/unused-My-Wallet-V3-jar

public Pair encryptAndWrapPayload(String password)
  throws JsonProcessingException, UnsupportedEncodingException, EncryptionException, NoSuchAlgorithmException {
  int iterations = walletBody.getOptions().getPbkdf2Iterations();
  String encryptedPayload = AESUtil.encrypt(walletBody.toJson(), password, iterations);
  WalletWrapper wrapperBody = WalletWrapper.wrap(encryptedPayload, iterations);
  String checkSum = new String(Hex.encode(MessageDigest.getInstance("SHA-256").digest(wrapperBody.toJson().getBytes("UTF-8"))));
  return Pair.of(checkSum, wrapperBody);
}

代码示例来源:origin: blockchain/unused-My-Wallet-V3-jar

public static synchronized Call<ResponseBody> publishTransaction(Transaction transaction, String apiCode)
    throws IOException {

    log.info("Publishing transaction");
    PushTx pushTx = new PushTx(BlockchainFramework.getRetrofitExplorerInstance(), apiCode);
    return pushTx.pushTx(new String(Hex.encode(transaction.bitcoinSerialize())));
  }
}

相关文章

微信公众号

最新文章

更多