io.nuls.core.tools.crypto.Hex.encode()方法的使用及代码示例

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

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

Hex.encode介绍

[英]对字节数据进行16进制编码。
[中]对字节数据进行16进制编码。

代码示例

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

@Override
public String toString() {
  return Hex.encode(bytes);
}

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

/**
 * 获取私匙转16进制后的字符串
 *
 * @return String
 */
@JsonIgnore
public String getPrivateKeyAsHex() {
  return Hex.encode(getPrivKeyBytes());
}

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

public static String getTxHash(byte[] fromBytes) {
  byte[] txBytes = getTxHashBytes(fromBytes);
  if(txBytes != null) {
    return Hex.encode(txBytes);
  }
  return null;
}

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

public static String getTxHash(byte[] fromBytes) {
  byte[] txBytes = getTxHashBytes(fromBytes);
  if(txBytes != null) {
    return Hex.encode(txBytes);
  }
  return null;
}

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

public String getPublicKeyAsHex(boolean compressed) {
  return Hex.encode(getPubKey(compressed));
}

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

@Override
  public String toString() {
    try {
      return Hex.encode(serialize());
    } catch (IOException e) {
      Log.error(e);
      return super.toString();
    }
  }
}

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

private int findSigInRedeem(byte[] signatureBytes, Sha256Hash hash) {
  checkArgument(chunks.get(0).isOpCode()); // P2SH scriptSig
  int numKeys = Script.decodeFromOpN(chunks.get(chunks.size() - 2).opcode);
  /* TransactionSignature signature = TransactionSignature.decodeFromBitcoin(signatureBytes, true);
  for (int i = 0 ; i < numKeys ; i++) {
    if (ECKey.fromPublicOnly(chunks.get(i + 1).data).verify(hash, signature)) {
      return i;
    }
  }*/
  throw new IllegalStateException("Could not find matching key for signature on " + hash.toString() + " sig " + Hex.encode(signatureBytes));
}

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

@Override
public String toString() {
  StringBuilder buf = new StringBuilder();
  if (isOpCode()) {
    buf.append(getOpCodeName(opcode));
  } else if (data != null) {
    // Data chunk
    buf.append(getPushDataName(opcode)).append("[").append(Hex.encode(data)).append("]");
  } else {
    // Small num
    buf.append(Script.decodeFromOpN(opcode));
  }
  return buf.toString();
}

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

public String getDigestHex() {
  try {
    return Hex.encode(serialize());
  } catch (IOException e) {
    Log.error(e);
    return null;
  }
}

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

public MultiSigAccountDto(MultiSigAccount account) {
  this.address = account.getAddress().getBase58();
  this.pubkeys = new ArrayList<>();
  for (byte[] bytes : account.getPubKeyList()) {
    Map<String, String> map = new HashMap<>();
    map.put("pubkey", Hex.encode(bytes));
    map.put("address", AddressTool.getStringAddressByBytes(AddressTool.getAddress(bytes)));
    pubkeys.add(map);
  }
  this.m = account.getM();
  this.alias = account.getAlias();
  if (null == alias) {
    this.alias = "";
  }
}

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

public AccountKeyStoreDto(AccountKeyStore accountKeyStore) {
  this.address = accountKeyStore.getAddress();
  this.encryptedPrivateKey = null == accountKeyStore.getEncryptedPrivateKey() ? null : accountKeyStore.getEncryptedPrivateKey();
  this.alias = accountKeyStore.getAlias();
  this.pubKey = Hex.encode(accountKeyStore.getPubKey());
  this.prikey = null == accountKeyStore.getPrikey() ? null : Hex.encode(accountKeyStore.getPrikey());
}

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

@Override
public Script getRedeemScript(MultiSigAccount multiSigAccount) {
  try {
    List<String> pubkeys = new ArrayList<>();
    if (multiSigAccount.getPubKeyList() != null && multiSigAccount.getM() > 0
        && multiSigAccount.getPubKeyList().size() >= multiSigAccount.getM()) {
      for (byte[] pubkeyByte : multiSigAccount.getPubKeyList()) {
        pubkeys.add(Hex.encode(pubkeyByte));
      }
      return ScriptBuilder.createNulsRedeemScript((int) multiSigAccount.getM(), pubkeys);
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
  return null;
}

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

public AccountOfflineDto(Account account) {
  this.address = account.getAddress().getBase58();
  this.alias = account.getAlias();
  this.pubKey = Hex.encode(account.getPubKey());
  this.createTime = account.getCreateTime();
  if (account.getExtend() != null) {
    this.extend = Hex.encode(account.getExtend());
  }
  this.encrypted = account.isEncrypted();
  if (encrypted) {
    this.encryptedPriKey = Hex.encode(account.getEncryptedPriKey());
    this.priKey = "";
  } else {
    this.priKey = Hex.encode(account.getPriKey());
    this.encryptedPriKey = "";
  }
  this.remark = account.getRemark();
}

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

public static String sha3(byte[] bytes, int bitLength) {
  Digest digest = new SHA3Digest(bitLength);
  digest.update(bytes, 0, bytes.length);
  byte[] rsData = new byte[digest.getDigestSize()];
  digest.doFinal(rsData, 0);
  return Hex.encode(rsData);
}

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

public static String keccak(byte[] bytes, int bitLength) {
  Digest digest = new KeccakDigest(bitLength);
  digest.update(bytes, 0, bytes.length);
  byte[] rsData = new byte[digest.getDigestSize()];
  digest.doFinal(rsData, 0);
  return Hex.encode(rsData);
}

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

public AccountDto(Account account) {
  this.address = account.getAddress().getBase58();
  this.alias = account.getAlias();
  this.pubKey = Hex.encode(account.getPubKey());
  this.createTime = account.getCreateTime();
  if (account.getExtend() != null) {
    this.extend = Hex.encode(account.getExtend());
  }
  this.encrypted = account.isEncrypted();
  this.remark = account.getRemark();
}

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

@Override
public Result saveUtxo(byte[] owner, Coin coin) {
  try {
    Log.info("save utxo::" + Hex.encode(owner));
    return dbService.put(LedgerStorageConstant.DB_NAME_LEDGER_UTXO, owner, coin.serialize());
  } catch (IOException e) {
    Log.error(e);
    return Result.getFailed(KernelErrorCode.IO_ERROR);
  }
}

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

public Result getEncryptedPrivateKey(String address, String priKey, String password) {
  if (!ECKey.isValidPrivteHex(priKey)) {
    return Result.getFailed(AccountErrorCode.PARAMETER_ERROR);
  }
  Account account;
  try {
    account = AccountTool.createAccount(priKey);
    if (!address.equals(account.getAddress().getBase58())) {
      return Result.getFailed(AccountErrorCode.PARAMETER_ERROR);
    }
    account.encrypt(password);
  } catch (NulsException e) {
    return Result.getFailed(AccountErrorCode.FAILED);
  }
  return Result.getSuccess().setData(Hex.encode(account.getEncryptedPriKey()));
}

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

public CreateContractDataDto(CreateContractData create) {
  this.sender = AddressTool.getStringAddressByBytes(create.getSender());
  this.contractAddress = AddressTool.getStringAddressByBytes(create.getContractAddress());
  this.value = create.getValue();
  this.hexCode = Hex.encode(create.getCode());
  this.gasLimit = create.getGasLimit();
  this.price = create.getPrice();
  this.argsCount = create.getArgsCount();
  this.args = create.getArgs();
}

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

public static TransactionCreatedReturnInfo makeReturnInfo(Transaction tx) throws IOException {
    String hash = NulsDigestData.calcDigestData(tx.serializeForHash()).getDigestHex();
    String txHex = Hex.encode(tx.serialize());
    CoinData coinData = tx.getCoinData();
    List<InputDto> inputs = ConvertCoinTool.convertInputList(coinData.getFrom());
    List<OutputDto> outputs = ConvertCoinTool.convertOutputList(coinData.getTo(), hash);
    TransactionCreatedReturnInfo returnInfo = new TransactionCreatedReturnInfo(hash, txHex, inputs, outputs);
    return returnInfo;
  }
}

相关文章